Articles in this section
Category / Section

How to change legend position in Blazor Chart?

5 mins read

This article explains how to change the legend position in Blazor Chart Component.

Customize the legend position

You can change the position of the legend using the Position property in ChartLegendSettings. By default, the legend position is set to Auto, which is determined by the area type of the chart.

The Position property includes the following options:

  • Auto - Places the legend based on the area type.
  • Top - Displays the legend at the top of the chart.
  • Bottom - Displays the legend at the bottom of the chart.
  • Right - Displays the legend at the right of the chart.
  • Left - Displays the legend at the left of the chart.
  • Custom(using X and Y coordinates) - Displays the legend based on the given x and y values.

In the following code example, the legend can be positioned at the left by using the Position property.

Index.razor


@using Syncfusion.Blazor.Charts

<SfChart Title="Olympic Medals">
    <ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category" />

    <ChartSeriesCollection>
        <ChartSeries DataSource="@MedalDetails" Name="Gold" XName="Country" Width="2" Opacity="1" YName="Gold" Type="ChartSeriesType.Column" />
        <ChartSeries DataSource="@MedalDetails" Name="Silver" XName="Country" Width="2" Opacity="1" YName="Silver" Type="ChartSeriesType.Column" />
        <ChartSeries DataSource="@MedalDetails" Name="Bronze" XName="Country" Width="2" Opacity="1" YName="Bronze" Type="ChartSeriesType.Column" />
    </ChartSeriesCollection>

    <ChartLegendSettings Visible="true" Position="LegendPosition.Left"/>
</SfChart>

@code {

    public class ChartData
    {
        public string Country { get; set; }
        public double Gold { get; set; }
        public double Silver { get; set; }
        public double Bronze { get; set; }
    }

    public List<ChartData> MedalDetails = new List<ChartData>
    {
        new ChartData{ Country= "USA", Gold=50, Silver=70, Bronze=45 },
        new ChartData{ Country="China", Gold=40, Silver= 60, Bronze=55 },
        new ChartData{ Country= "Japan", Gold=70, Silver= 60, Bronze=50 },
        new ChartData{ Country= "Australia", Gold=60, Silver= 56, Bronze=40 },
        new ChartData{ Country= "France", Gold=50, Silver= 45, Bronze=35 },
        new ChartData{ Country= "Germany", Gold=40, Silver=30, Bronze=22 },
        new ChartData{ Country= "Italy", Gold=40, Silver=35, Bronze=37 },
        new ChartData{ Country= "Sweden", Gold=30, Silver=25, Bronze=27 }
    };
}

The screenshots below display the results of the aforementioned code.

Output:

Screenshot: Legend docked at Left

Left.png

Screenshot: Legend docked at Bottom

Buttom.png

Screenshot: Legend docked at Right

Right.png

Screenshot: Legend docked at Custom

Custom.png

View the sample in GitHub

Conclusion

I hope you enjoyed learning how to change legend position in Blazor Chart Component.

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)
Please  to leave a comment
Access denied
Access denied