Articles in this section
Category / Section

How to sort pie chart points in Blazor Charts?

3 mins read

This article explains how to sort pie chart points.

Sorting accumulation chart points

Blazor Charts provides an option to sort the accumulation chart data points at initial rendering and also dynamically. This can be achieved using OrderBy clause which sorts the group in either ascending or descending order.

In OnInitialized method, you can sort the points using y value and assign sorted list to chart datasource for sorting values at initial rendering. For dynamic sorting, the same scenario can be achieved through button click.

The below code example 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

image.png

Live Sample for Sorting Pie Points

Conclusion

I hope you enjoyed learning how to sort pie chart points 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)
Please  to leave a comment
Access denied
Access denied