Sort legend labels in a C1ChartLegend of a C1Chart?

Posted by: wkelly1 on 20 July 2018, 12:10 pm EST

    • Post Options:
    • Link

    Posted 20 July 2018, 12:10 pm EST - Updated 4 October 2022, 9:18 am EST

    The order of the items in my legend is currently determined by the order that the items are added to the SeriesItemsSource. (My SeriesItemSource is an ObservableCollection<'T>.)

    I would like custom sort the labels that appear in the legend. For example, I might want the list to be alphabetical.

    I could add the items to the SeriesItemsSource in an alphabetical order. However, the items are currently added asynchronously and I would rather not give up that feature.

    I could re-sort the ObservableCollection<'T> every time I add a new item. However, I’m assuming that would result in all the previously added data series being replotted with every additional item.

    What is the best way to sort the labels listed in the legend?

  • Posted 23 July 2018, 3:29 am EST

    Hello,

    As C1ChartLegend inherits from ItemsControl, you can specify how the items(i.e Legend Items) in the collection are sorted using SortDescriptions method as shown in the example below:

    legend.Items.SortDescriptions.Add(new System.ComponentModel.SortDescription("Label", System.ComponentModel.ListSortDirection.Ascending));
    
    

    Please refer the attached sample for the same.

    Thank you.

    prj_LegendOrdering.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels