How to sort pie chart points in Blazor Charts?
This article explains how to sort pie chart points in Blazor Charts.
Sorting Accumulation Chart Points
Blazor Charts provides an option to sort accumulation chart data points both at initial rendering and dynamically. This can be achieved using the OrderBy clause, which sorts the group in either ascending or descending order.
In the OnInitialized method, you can sort the points using y value and assign the sorted list to the chart datasource for sorting values at initial rendering. For dynamic sorting, the same scenario can be achieved through a button click.
The code example below demonstrates how to sort accumulation chart points.
Index.razor:
@using Syncfusion.Blazor.Charts
<SfAccumulationChart Title="Mobile Browser Statistics" EnableSmartLabels="true">
<AccumulationChartLegendSettings Visible="false"></AccumulationChartLegendSettings>
<AccumulationChartSeriesCollection>
<AccumulationChartSeries DataSource="@StatisticsDetails" XName="Browser" YName="Users" Name="Browser">
<AccumulationDataLabelSettings Visible="true" Name="Browser"></AccumulationDataLabelSettings>
</AccumulationChartSeries>
</AccumulationChartSeriesCollection>
</SfAccumulationChart>
@code {
public class Statistics
{
public string Browser { get; set; }
public double Users { get; set; }
public string Text { get; set; }
public string Fill { get; set; }
}
public List<Statistics> StatisticsDetails = new List<Statistics>
{
new Statistics { Browser = "Chrome", Users = 37, Text= "37%", Fill="#498fff"},
new Statistics { Browser = "UC Browser", Users = 17, Text= "17%", Fill="#ffa060"},
new Statistics { Browser = "iPhone", Users = 19, Text= "19%", Fill="#ff68b6"},
new Statistics { Browser = "Opera", Users = 11, Text= "11%", Fill="#b2cfff"},
new Statistics { Browser = "Android", Users = 12, Text= "12%", Fill="#ff7b66"},
new Statistics { Browser = "Edge", Users = 8, Text= "8%", Fill="#4e7ac7"},
new Statistics { Browser = "Safari", Users = 16, Text= "16%", Fill="#81e2a1"},
new Statistics { Browser = "Firefox", Users = 9, Text= "9%", Fill="#ff8040"},
new Statistics { Browser = "Internet Explorer", Users = 5 , Text= "5%", Fill="#bfbfbf"},
new Statistics { Browser = "Samsung Internet", Users = 7, Text= "7%", Fill="#ff944d"}
};
protected override void OnInitialized()
{
StatisticsDetails = StatisticsDetails.OrderBy(x => x.Users).ToList();
}
}
The following screenshot illustrates the output of the code snippet:
Output:
Live Sample for Sorting Pie Points
Conclusion:
We hope you enjoyed learning how to sort pie chart points in Blazor Charts.
You can refer to our Blazor Chart feature tour page to learn about its other groundbreaking features, documentation, and how to quickly get started with configuration specifications. You can also explore our Blazor Chart example to understand how to create and manipulate data.
For current customers, our Blazor components are available on the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to evaluate our Blazor charts and other Blazor components.
If you have any questions 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!