Author Topic: trend chart overview  (Read 6286 times)

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
trend chart overview
« on: January 17, 2016, 09:02:26 PM »
Archie, I am looking to do some trending of several values of a controller.  I see a few options such as the BasicTrendChart, ChartByArray, and ChartBySampling.  Could you give a brief overview of how to set up these these controls as Im not sure the difference between the later two.  Doing some testing with the ChartbySampling, I notice the Y axis does not auto scale after a few seconds of sampling.  Also is there anyway to add additional trends to the BasicTrendChart?  Thank you

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: trend chart overview
« Reply #1 on: January 17, 2016, 09:21:03 PM »
The BasicTrendChart is only setup for a single line. It is the most basic and the fastest.

ChartByArray will read an array of values from the PLC and plot the values. This could be used in a case where you need very precise sample intervals and use a timer in the PLC to sample the points and store them in an array.

ChartBySampling only looks at a single register and plots it every specified time interval. Because this relies on Windows timing it will not be persistent.

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: trend chart overview
« Reply #2 on: January 18, 2016, 07:52:31 AM »
Thanks Archie.  I did find that I can trend several registers on a single graph with the ChartBySampling by adding series.  My problem is I would like to graph the same register from different controllers on the same graph.  I guess I will add this to the feature request on the next release.  Thanks 

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: trend chart overview
« Reply #3 on: January 18, 2016, 08:10:26 AM »
You are correct, you can only graph from the same controller since only a single ComComponent can be specified for each chart.

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: trend chart overview
« Reply #4 on: January 18, 2016, 09:04:42 PM »
Ok with some tinkering with a standard chart control I can now trend the same register from multiple controllers.  I would like to be able to scroll left and right to see past values but I am stuck on how to be able to do this.  I would like to have this to happen on a simple button click as I am limited to space but I can add a scrollbar if needed. Any help is appreciated, thanks!

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: trend chart overview
« Reply #5 on: January 20, 2016, 08:09:11 AM »
Hey Archie, I have come up empty on my quest to find a way to add these controls to the fastline chart.  I would like to add 4 buttons to the form to control these functions of the graph.. PAUSE,PLAY,SCROLL LEFT,SCROLL RIGHT.  Can you get me started in the right direction?  Thanks.   

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: trend chart overview
« Reply #6 on: January 20, 2016, 09:16:36 AM »
This is really a sizable task. It will be almost a complete re-write of the trending chart.

One approach is to create a new User Control, add a BasicTrendingChart to the control, then add the navigation buttons. It would then require a fair amount of code to make it only display segments of the captured data.

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: trend chart overview
« Reply #7 on: January 24, 2016, 10:08:43 AM »
Archie, I almost have this working perfectly except one issue.  I used a standard fastline chart control and was able to do everything I needed with some basic code. However, here is my issue:  I have a fastline chart with 5 series, each series receives data from a different device.  I can start or stop each chart or series individually.  The Y axis is the data and the X axis is the PC time.  If I start all series at the same time, everything works great.  However if I decide to start a series after the first, its X axis value does not equal the others that are still running.  This causes an event to be indicated at the wrong time along the X axis.  How can I make sure the Xaxis of each series is at the same point?  The pic attached shows two devices where the blue line was started about 15 sec after the red line.  The changes in the Y axis are the same for both devices, however the blue line indicates this happens at the wrong time.  Is there a way to fix this?  Thanks

BLFTech

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • BLF-Tech LLC Website
Re: trend chart overview
« Reply #8 on: February 14, 2016, 03:41:28 PM »
Would you be willing to share this code? I need to graph temperature data points and be able to scroll back and forth for historical data.

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: trend chart overview
« Reply #9 on: February 16, 2016, 09:57:13 PM »
Gladly, I will try to post some snippets and explain them the best I can.  I have this working perfectly for my application, hope it works for yours.  I used a standard fastline control not the AHMI control only because I wanted to trend the same register of 5 different controllers.

The first thing I did was set the size of the trend window.  This was to prevent compression of the lines after running a long time.  The value of 500 was an arbitrary number as I found this to do well for my application
  '********************************************************************************************************************************
    'The following code sets the size of the chart so that the data on the X axis does not get compressed
    'The Chart accumulator holds the last position so that it can prevent over scrolling to the right
    ' "TIME" is current PC time
    '********************************************************************************************************************************

    Dim Chart1Accumulator, Chart2Accumulator, Chart3Accumulator, Chart4Accumulator, Time As String
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Time = DateAndTime.Now.ToString("h:mm:ss")
        Chart1.ChartAreas(0).AxisX.Minimum = (Chart1.ChartAreas(0).AxisX.Maximum - 500)
        Chart2.ChartAreas(0).AxisX.Minimum = (Chart2.ChartAreas(0).AxisX.Maximum - 500)
        Chart3.ChartAreas(0).AxisX.Minimum = (Chart3.ChartAreas(0).AxisX.Maximum - 500)
        Chart4.ChartAreas(0).AxisX.Minimum = (Chart4.ChartAreas(0).AxisX.Maximum - 500)


As for scrolling, I simply added a button with this code to decrement the chart maximum value by 100
'********************************************************************************************************************************
    'The following code allows for scrolling left of chart 2
    '********************************************************************************************************************************
    Private Sub ScrollLeft2_Click(sender As Object, e As EventArgs) Handles ScrollLeft2.Click
        If PAUSE2.Visible = False Then
            Chart2.ChartAreas(0).AxisX.Minimum = Chart2.ChartAreas(0).AxisX.Minimum - 100
            Chart2.ChartAreas(0).AxisX.Maximum = Chart2.ChartAreas(0).AxisX.Maximum - 100
        End If
    End Sub


Scroll the other way

    '********************************************************************************************************************************
    'The following code allows for scrolling right of chart 2
    '********************************************************************************************************************************
    Private Sub ScrollRight2_Click(sender As Object, e As EventArgs) Handles ScrollRight2.Click
        If PAUSE2.Visible = False Then
            If Chart2.ChartAreas(0).AxisX.Maximum <= Chart2Accumulator Then
                Chart2.ChartAreas(0).AxisX.Minimum = Chart2.ChartAreas(0).AxisX.Minimum + 100
                Chart2.ChartAreas(0).AxisX.Maximum = Chart2.ChartAreas(0).AxisX.Maximum + 100
            ElseIf Chart2.ChartAreas(0).AxisX.Maximum > Chart2Accumulator Then
                MsgBox("END OF CHART REACHED")
            End If
        End If
    End Sub


Actually plotting the data was accomplished by always plotting the X axis as PC time but the trick was to set the y value to "Double.NAN" when you didn't want it to graph.  This allowed you to start and stop each graph and always have each series at the same X value of PC time.


  Chart1Accumulator = Chart1.ChartAreas(0).AxisX.Maximum
            If CheckBox1.Checked = True Then
                CHART1GEN1 = BasicLabel1.Text
            Else
                CHART1GEN1 = Double.NaN
            End If Chart1.Series("Gen 1").Points.AddXY(Time, CHART1GEN1)


This is of course a condensed version, so let me know if I can be of further help.  Hope this works for you. 

Markfish54

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: trend chart overview
« Reply #10 on: May 17, 2016, 01:46:35 PM »
MrPike,

Thank you very much for posting this. I am very new to VB but I really like the ADHMI that Archie (Hats off to you) has created. I am trying to create a similar chart. I am accessing only one controller and also using ChartBySampling and the fastline with 7 different series. I tried to implement your code but could not get it to work (my newness to VB). What you have done is what I'm try to re-create, scroll right and left and the pc time along the bottom of the chart. Is the something I could get you to explain further.

Thank you in advance,
Mark

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: trend chart overview
« Reply #11 on: May 17, 2016, 02:38:23 PM »
Sure. Try this post and see if it helps you. I posted my trend chart and entire code here. Let me know if you have any further questions.

http://advancedhmi.com/forum/index.php?topic=1281.msg6801#msg6801

Markfish54

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: trend chart overview
« Reply #12 on: May 17, 2016, 06:54:54 PM »
Thank you MrPike!