none
Naming individual labels at runtime in single series

    Question

  • My application allows users to query a database and add events on a timeline at runtime. Based on combo box selections, a datarow called EventQuery is determined and adds events in a single series (called events). Like this:

                    For Each dr As DataRow In EventQuery
                        ch1.Series("Events").Points.AddXY(dr(strDate), (0))
                        intCount += 1
                    Next

    It then adds labels to the new points in "Events"

                cht1.Series("Events").Label = " " & cboColumn.SelectedItem & " " &  txtConstraint.Text

    Users are able to do this multiple times, adding new points after each button press. The problem is ALL labels in the series are updated with each button press, rather than just the newly added points, so it's impossible to distinguish a new group of points from previous ones.

    Any ideas as to how I can add labels for only each group of points in a series, rather than the entire series? Thanks in advance.

    Thursday, January 17, 2013 7:37 PM

Answers

  • Create a DataPoint object in the loop and use the DataPoint.Label property set the label.

    For Each dr As DataRow In EventQuery
    
    	Dim dp As New DataPoint()
    	dp.SetValueXY(dr(strDate), (0))
    	dp.Label = " " & cboColumn.SelectedItem & " " & txtConstraint.Text
    
    	ch1.Series("Events").Points.Add(dp)
    
    	intCount += 1
    
    Next

    • Marked as answer by Noolybum Friday, January 18, 2013 6:51 PM
    • Unmarked as answer by Noolybum Tuesday, January 22, 2013 4:09 PM
    • Edited by siplaModerator Tuesday, January 22, 2013 6:52 PM fixed code
    • Marked as answer by Noolybum Wednesday, February 13, 2013 5:58 PM
    Friday, January 18, 2013 7:42 AM

All replies

  • Create a DataPoint object in the loop and use the DataPoint.Label property set the label.

    For Each dr As DataRow In EventQuery
    
    	Dim dp As New DataPoint()
    	dp.SetValueXY(dr(strDate), (0))
    	dp.Label = " " & cboColumn.SelectedItem & " " & txtConstraint.Text
    
    	ch1.Series("Events").Points.Add(dp)
    
    	intCount += 1
    
    Next

    • Marked as answer by Noolybum Friday, January 18, 2013 6:51 PM
    • Unmarked as answer by Noolybum Tuesday, January 22, 2013 4:09 PM
    • Edited by siplaModerator Tuesday, January 22, 2013 6:52 PM fixed code
    • Marked as answer by Noolybum Wednesday, February 13, 2013 5:58 PM
    Friday, January 18, 2013 7:42 AM
  • I've tried several variations of this (such as declaring dp before the loop, etc) and still get the 'too many y values' problem.
    Tuesday, January 22, 2013 5:06 PM
  • And just a picture to give you a better idea of what it's saying:





    • Edited by Noolybum Tuesday, January 22, 2013 5:57 PM
    Tuesday, January 22, 2013 5:56 PM
  • Instead of the AddXY method, use the Add method. I fixed the bug in my previous post.
    Tuesday, January 22, 2013 6:54 PM
  • Thanks for adding that, Sipla. This works, but the problem is now that after I click the button a second time, the previous point disappears entirely, and only the new point(s) remain! :(

    Tuesday, January 22, 2013 7:18 PM