.netCHARTING v4.4 Documentation Send comments on this topic.
Element Sorting
Getting Started > Data Tutorials > Data Manipulation > Element Sorting

Glossary Item Box

Introduction

This tutorial will describe how elements can be sorted.

Quantitative axis Sorting

Elements with numeric or dateTime x values and a numeric or dateTime x axis will automatically fall into place where the values on the axis appear. Elements may contain names as well as x values such as dates, however, if both values exist, the x axis will behave as a category axis which shows names of the elements. To force the axis to use a time scale the follwing code can be used

[C#]
Chart.XAxis.Scale = Scale.Time;
[Visual Basic]
Chart.XAxis.Scale = Scale.Time

If the elements have names and numbers using Scale.Normal will have the same effect for numbers causing the x axis to become a numeric axis.

 

Single Series Sorting

A single series of elements with names instead of x values will be drawn on the chart in the order the elements are added to the series.

The series class offers sorting methods that allow the elements to be sorted by any value. This line of code will sort the elements by their Y values in ascending order:

[C#]
mySeries.Sort(ElementValue.YValue, "asc");
[Visual Basic]
mySeries.Sort(ElementValue.YValue, "asc")
TIP: To reverse the order of elements on an axis, it can be done quickly by using Chart.XAxis.InvertScale = true

 

Multiple Series Sorting

If multiple series are added to the chart with the same element names and in the same order the chart will draw them in the order they are added. When multiple series with elements that are different are added, the chart performs some smart grouping functionality that processes the sort order.This section will describe the element name grouping functionality.

 

As an example case, elements will be provided for the chart in a segmented order.

3 Series, each with 4 elements: 

Series 1: C D E F
Series 2: E F G H
Series 3: A B C D

SeriesCollection.SmartGrouping = true (Default)

Intended order:

A B C D E F G H

.netCHARTING Will analyze this list and determine what the true intended order should be. This does not employ sorting, it looks for patterns in element orders of different series to determine the original order. In this case the available element names offer enough information to determine the sort order to be the above.

SeriesCollection.SmartGrouping = false

When false, the element order will be based on the orders in which series elements are provided. The above example will result in this order:

 

C D E F G H A B

The frist series defines the order to be CDEF then the second series has two new element names which are added at the end GH. The final series offers AB as new names and that will be added at the end and so on.

 

Despite any sorting performed on series, if the x axis is a category axis, the above processing will be applied.