Articles in this section

How to place the legend at a custom location in Blazor Charts?

This article explains how to place the legend at a custom location in Blazor Charts.

Place the Legend at a Custom Location

Blazor Charts provides an option to place the legend at a custom location. The ChartLocation is used to set the position of the legend. By specifying X and Y values within ChartLegendSettings, you can define the exact position of the legend on the chart, allowing for custom positioning using these X and Y offsets.

In this code snippet, the ChartLegendSettings is used to customize the position of the legend in a chart. By setting the Position property to LegendPosition.Custom and providing specific X and Y values through the ChartLocation, you can precisely place the legend at the desired location on the chart.

@using Syncfusion.Blazor.Charts

<SfChart>
   <ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
   <ChartSeriesCollection>
       <ChartSeries DataSource="@Sales" Name="Sales" XName="Month" YName="SalesValue" Type="ChartSeriesType.Column">
       </ChartSeries>
   </ChartSeriesCollection>
   <ChartLegendSettings Position="LegendPosition.Custom"  Visible="true">
       <ChartLocation X="30" Y="20"></ChartLocation>
   </ChartLegendSettings>
</SfChart>

@code {
   public class SalesInfo
   {
       public string Month { get; set; }
       public double SalesValue { get; set; }
   }

   public List<SalesInfo> Sales = new List<SalesInfo>
   {
       new SalesInfo { Month = "Jan", SalesValue = 35 },
       new SalesInfo { Month = "Feb", SalesValue = 28 },
       new SalesInfo { Month = "Mar", SalesValue = 34 },
       new SalesInfo { Month = "Apr", SalesValue = 32 },
       new SalesInfo { Month = "May", SalesValue = 40 },
       new SalesInfo { Month = "Jun", SalesValue = 32 },
       new SalesInfo { Month = "Jul", SalesValue = 35 }
   };
} 

The following screenshot illustrates the output of the code snippet.

msedge_0BwFO8KmyE.png

Live Sample for Placing the Legend at a Custom Location

Conclusion

I hope you enjoyed learning how to place the legend at a custom location in Blazor Charts.

You can refer to our Blazor Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Blazor Chart example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied