1

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. enter image description here

9
  • 1
    well you could do this in a foreach loop or a for loop and use the counter variable to concat / generate the label name .Text what you have shown really doesn't help much ... Commented Sep 1, 2016 at 19:06
  • Yes, except I'm getting the information fed in from a UDP port. So if there's a height that fits the criteria (eg. if Height >1.78), then this script gets triggered. I would accept suggestions in modifying the way I add the points if necessary. Furthermore, I could perhaps add the label for the current iteration... Commented Sep 1, 2016 at 19:11
  • 1
    well based on what you have shown nobody would know where it's being fed from since you didn't specify that in your original question also you are not posting code that relates to your current problem and or issue.. I would suggest editing the question and showing all relevant code that pertains to your problem and or issue Commented Sep 1, 2016 at 19:15
  • Okay, I've added the relevant code to get at more of what I'm trying to do. Once again, I'm trying to add the Height (convert to Double) if it passes my paramaters (if numberSize>paramSize). Then add the label from the UDP set of data. Commented Sep 1, 2016 at 19:26
  • 1
    Well you can add individual Labels to each DataPoint: Grab the index when you add it and then add a label: int idx = _form.chart1.Series["Series1"].Points.AddY(heightDouble); _form.chart1.Series["Series1"].Points[idx].Label = .... Do check out the Keyword Reference Commented Sep 1, 2016 at 21:31

1 Answer 1

4

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 = ... 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.