Reputation: 343
Right now, I have a chart and I add Y value points. Followed by the label. But when I go on to add more points, the current label is the same for all points. Is there a way I can make each label have the correct one?
chart1.Series["Series1"].Points.AddY(Height);
chart1.Series["Series1"].Label = Age;
Maybe, I can add the label Age in the same line I add the datapoint Height? (Eg. (Height, Label=Age))?
Above is the basic concept I'm trying to fix. The essence of what I'm doing is getting a UDP feed when the "height" paramater fits my criteria (above 1.78). Then, after converting the height string to double, I add it to the chart plot. And then add the corresponding label in the UDP. Only problem is, on the next point, all my points get the same label when it updates.
Age is a string, that I'm using as a label, it is not to be used in the Xaxis or Yaxis
if (numberSize>paramSize) //if myHeight is greater than paramHeight
{
if (_form.listBox1.InvokeRequired)
_form.listBox1.Invoke((MethodInvoker)delegate ()
{
_form.listBox1.Items.Insert(0, valueSet);
// below just converting to double to be fitted in my chart
double heightDouble = Convert.ToDouble(Height);
//And now I'd like to add a point from the UDP and then its label
_form.chart1.Series["Series1"].Points.AddY(heightDouble);
_form.chart1.Series["Series1"].Label = Age;
}
);
}
Thanks
P.S. To make things clearer, below is the graph. On the Y-axis is Height. X-axis is simply that iteration of the point (eg. 2nd point, 3rd point, etc.), the label is the age. The last age was 72, but every label gets set as 72, not only for the current one.
Upvotes: 1
Views: 9421
Reputation: 343
It worked when I used the answer from TaW.
int idx = _form.chart1.Series["Series1"].Points.AddY(heightDouble);
_form.chart1.Series["Series1"].Points[idx].Label = ...
Upvotes: 4