Author Topic: VB chart component scrolling x-axis?  (Read 2575 times)

doggo

  • Newbie
  • *
  • Posts: 23
    • View Profile
VB chart component scrolling x-axis?
« on: January 19, 2015, 05:15:53 PM »
AHMI folks,

Anyone know a good way to configure the VB chart component so the x-axis (time) will scroll off the screen to the left as new values populate the screen on the right side?  I did google this and there seem to be some half-examples of code which changes the min and max ChartAreas properties. Not a VB God here so a specific example showing how to implement this with using the VB timer (like in Archie's examples) control as the tick source would be great.

Archie, you may be working on a similar advanced trend control for later release, hopefully it will have lots of options to configure time-based trend scrolling, because although the VB chart is powerful, it really isn't that easy to use for time-based trending.

Thanks,
Doggo


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: VB chart component scrolling x-axis?
« Reply #1 on: January 19, 2015, 08:32:28 PM »
The points on the chart is a collection, which is essentially a self growing array. Collections have many useful methods. One of those is a method named RemoveAt. This method will let you remove items any where in the collection. So let's say you wanted to remove the oldest item in the collection:

MyCollection.RemoveAt(0)

Now apply that to a point collection on a chart.


        Chart1.Series(0).Points.Add(MyNewValue)
        '* Limit to 100 points
        If Chart1.Series(0).Points.Count > 100 Then
            Chart1.Series(0).Points.RemoveAt(0)
        End If

doggo

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: VB chart component scrolling x-axis?
« Reply #2 on: January 19, 2015, 10:58:09 PM »
Archie,

I had an example of code that went like this;

 If Chart1.Series.Count > 100 Then
            Chart1.Series(0).Points.RemoveAt(0)
            Chart1.Series(1).Points.RemoveAt(0)

and it woudn't work- points would not come off the left side...NOW I see why! ( If Chart1.Series(0).Points.Count)

What is the 100 point limit about? Is that a VB limit or an arbitrary limit based on typical PC CPU speed?  Ideally, we would like to have two trend collections displayed over about 30 minutes along the same x-axis, but each collection is being scanned about 4 times a second...7200 pts/collection.



Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: VB chart component scrolling x-axis?
« Reply #3 on: January 19, 2015, 11:04:10 PM »
The 100 is just an arbitrary number. You can make it however many points you want to keep on the chart. Of course, if you get too carried away, your PC may run out of memory.

doggo

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: VB chart component scrolling x-axis?
« Reply #4 on: January 20, 2015, 02:42:36 PM »
Using the VB chart component and your code corrections, I'm sucessfully trending two collections in an AHMI 1920 x 1080 screen which are 1000 points in length each, no problem or delay updating 4 times a second. Talking to an L71 CLX processor. Gonna try 3500 points. PC is mid-range intel I5 w 8GB ram.

Well done Archie!


 

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: VB chart component scrolling x-axis?
« Reply #5 on: January 20, 2015, 02:47:42 PM »
Nice. You'll have to put a screen shot of it in the application showcase when you are finished with it.