Skip to main content

Sorting Data

  • 2 minutes to read

You can sort auto-created series by name in ascending or descending order. If you use qualitative series, you can choose whether to sort points by arguments or values.

This topic consists of the following sections:

Sort Series

The Chart Control sorts series by name. The names of automatically generated series are obtained from a data source’s field specified via the ChartControl.SeriesDataMember property.

The ChartControl.SeriesSorting property allows you to toggle between ascending and descending order, and affects the order of series in the chart’s diagram and legend.

The following images illustrate this property:

The property’s value Resulting image
SeriesSorting = None SeriesSorting_None
SeriesSorting = Ascending SeriesSorting_Ascending
SeriesSorting = Descending SeriesSorting_Descending

The following code sorts series in ascending order:

chartControl1.SeriesSorting = SortingMode.Ascending;

To sort series you created, change their order in the ChartControl.Series collection.

Sort Series Points

The Chart Control can sort series with qualitative arguments (SeriesBase.ArgumentScaleType is set to Qualitative) only. Use the SeriesBase.SeriesPointsSorting property to specify how to sort series points (ascending, descending, or none). The SeriesBase.SeriesPointsSortingKey property defines whether to sort series points by their arguments or values.

SeriesPointsSortingKey

The following images show the modes that are available for the SeriesBase.SeriesPointsSorting property when series points are sorted by values:

Property values

Resulting image

SeriesPointsSorting = None

SeriesPointsSortingKey = Value

SeriesPointSorting_none

SeriesPointsSorting = Ascending

SeriesPointsSortingKey = Value

SeriesPointSorting_ascend

SeriesPointsSorting = Descending

SeriesPointsSortingKey = Value

SeriesPointSorting_descend

The following code sorts points by values in ascending order:

SeriesBase seriesTemplate = chartControl1.SeriesTemplate;
seriesTemplate.SeriesPointsSorting = SortingMode.Ascending;
seriesTemplate.SeriesPointsSortingKey = SeriesPointKey.Value_1;

You can also implement a comparer that specifies a custom order for qualitative x-axis arguments. Refer to the Reorder Qualitative Axis Values section for more information.

See Also