Reputation: 305
The .net desktop-application receives response from the micro-controller and plots the data to the graph on time interval basis. If you look into the red-circled x-axis labels, you'll not find them in ordered manner. Eg. -20.0 should come before -20.4. The problem is, if you look into the code:
chart1.Series[0].Points.AddXY(rLabData[0], rLabData[1]);
'AddXY' according to msdn doc: Adds a DataPoint object to the end of the collection, with the specified X-value and Y-values(s). This is the problem, I don't not want the data points to be added at the end of previous result rather within the maximum and minimum value of X-axis defined in scale If the input points is given at the same instance it works fine, but upon regular interval basis, the chart in winform doesn't display desired result.
Upvotes: 1
Views: 1064
Reputation: 54433
Your first question can be answered: If you don't want the new DataPoints
to be added at the end of the Points
collection, you need to insert them at the right spot.
Here is an example for inserting a DataPoint(yourXValue, yourYValue)
into a Series S
:
// we try to find the DataPoint right after our X-Value:
DataPoint dp = S.Points.FirstOrDefault(p => p.XValue > yourXValue);
if (dp != null)
{
// got it, so we insert before it..
int index = S.Points.IndexOf(dp);
if (index >= 0) S.Points.InsertXY(index, yourXValue, yourYValue);
}
// no, so we add to the end
else S.Points.AddXY(yourXValue, yourYValue);
Unfortunately I have doubts that your Label
problem really is caused by adding..
Your chart looks like it is ChartType.Point
. For this type the order of the DataPoints
doesn't show, as opposed to other types, like Line
..
And the Labels
shouldn't be out of order with any type, unless you add (wrong) CustomLabels
..?
Upvotes: 1