There are some situations where your data points must
be sorted in Dundas Chart, but the data source does not
provide the data in order. For example, if you have
unsorted data
with a line chart you can see the line go back and forth across the
chart, or if you are using the
Chart.DataManipulator.Group()
method the points must be sorted.
Fortunately, Dundas Chart for .NET (all editions) and Dundas Chart
for SharePoint provide sorting functionality built-in. You can sort
your data by Y values, X values, or axis labels (string X values) with
one method call in code (in SharePoint, use the Chart Web Part's code
editor, accessible from the down-arrow menu in the top-right corner,
and select the PostApplyData event.)
Here are some examples that sort all series in the chart at once. This
assumes that all of your series are aligned, meaning the points in each
series have the same X values in the same order, and all of the series are
sorted together.
C#
chartObj.DataManipulator.Sort(PointsSortOrder.Ascending, "X", "*");
chartObj.DataManipulator.Sort(PointsSortOrder.Ascending, "AxisLabel", "*");
chartObj.DataManipulator.Sort(PointsSortOrder.Ascending, "*");
VisualBasic.NET
chartObj.DataManipulator.Sort(PointsSortOrder.Ascending, "X", "*")
chartObj.DataManipulator.Sort(PointsSortOrder.Ascending, "AxisLabel", "*")
chartObj.DataManipulator.Sort(PointsSortOrder.Ascending, "*")
If you want to sort individual series, you can pass the Series object,
or specify the series name instead of "*" as the second argument. Or, you
can call sort on the Series object. Here is an example that sorts each
series individually by X value (the series do not need to be aligned):
C#
foreach (Series series in chartObj.Series) {
series.Sort(PointsSortOrder.Ascending, "X");
}
VisualBasic.NET
For Each series As Series In chartObj.Series
series.Sort(PointsSortOrder.Ascending, "X")
Next
More tips on sorting by axis labels can be found in
this support
site article. For more general information, see "Sorting Data" in the
online help.
|