Hi,
I have a line chart and add NumericSeries in this chart.
the data like these: (7500, 16.1), (7600, 10.2), (7700, 19.9)
and then the user add (7300, 10.1).
the last data will be displayed in the last of the line, can it be inserted in front of 7500?
in other words, auto sort the labels in x-axis.
The chart itself will not perform any kind of sorting, but you can sort your datasource before you bind it to the chart. The chart displays the items in the same order as they are in the datasource.
Thanks for your reply.
because of implementing dragging the data point in this line chart, it didn't bind any datasource, in other words, it program added series and datapoints.
I referred to DraggingDataPointTool.cs in the local sample code to implement this dragging function, and when I bound to datasource, this function doesn't work.
could you provide the example for how to drag the data point when it bound to a datasource?
Actually, turns out that numeric data point collection does implement sorting, so you should be able to use mySeries.Points.Sort() to arrange your points. Let me know if that works for you.
After I use mySeries.Points.Sort(), it sort the values of Y-Axis, not the labels in X-Axis.
the type of my labels in X-Axis is the numeric.
Could you please tell me how to sort the labels in X-Axis?
Thanks a lot.
Ok, so you're using a LineChart with a NumericSeries. If that's the case, you must be supplying strings as your labels, even though they appear to be numeric. So, your data really looks more like ("7500", 16.1), ("7600", 10.2), ("7700", 19.9). Strings can't really be sorted like numbers by the Sort method, so you have to implement your own sorting.
Here's an example.
ultraChart1.ChartType = ChartType.LineChart;NumericSeries series = new NumericSeries();series.Points.Add(new NumericDataPoint(2, "40", false));series.Points.Add(new NumericDataPoint(5, "60", false));series.Points.Add(new NumericDataPoint(8, "80", false));series.Points.Add(new NumericDataPoint(10, "70", false));
for (int i = 0; i < series.Points.Count; i++){ for (int j = i + 1; j < series.Points.Count; j++) { double val1 = Double.Parse(series.Points[i].Label); double val2 = Double.Parse(series.Points[j].Label); if (val1 > val2) { NumericDataPoint temp = series.Points[i]; series.Points[i] = series.Points[j]; series.Points[j] = temp; } }}
ultraChart1.Series.Add(series);