Author Topic: Trend chart with events  (Read 3551 times)

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Trend chart with events
« Reply #15 on: March 13, 2018, 02:55:20 AM »
You will need a collection of strings to hold the description value for each event, just as done with the value collection.

My preferred method is to create a class that encapsulates the value and description string together. I updated my example program by adding an EventItem class. The new project is attached.

Godra's method of using annotations may be a cleaner or easier route. He showed the use of line annotations added to the chart, but I see there is also the option of adding text annotations. The annotation method lets you add the items, then let the chart handle the rendering.
« Last Edit: March 13, 2018, 02:58:18 AM by Archie »

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: Trend chart with events
« Reply #16 on: March 13, 2018, 09:06:01 PM »
Thanks Archie, works like a champ.  I did try Godra's approach with annotations but I could not get the annotations to move with the graph since I use this as a "live" data chart.  The chart moves off the screen but the annotations stay in the same place.  I may have done something wrong but this method works well.  I very much appreciate the help.  My next struggle is to rotate the text to hopefully print diagonally to a void overlapping long strings.  Thank you.     

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Trend chart with events
« Reply #17 on: March 13, 2018, 09:28:26 PM »
Just for the record, I just tried the chart from the other post with AUTO refresh and the annotation vertical lines did move as the graph was repainted.

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: Trend chart with events
« Reply #18 on: March 13, 2018, 09:39:11 PM »
Thanks Godra, I'm sure I did something wrong.  I did not use your control directly but rather tried to mimic your code to avoid having to redo all my work.  I appreciate all your help!

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: Trend chart with events
« Reply #19 on: March 14, 2018, 02:38:44 PM »
Archie, the last piece of my puzzle is to rotate the text of the event to print diagonally.  this would clean the chart up a lot and prevent overlapping on long strings.  However I cannot find the proper method to do this.  I have tried the drawstring.rotatetransform(45) but this seems to rotate the entire chart.  I cannot seem to pick out just the text from m_EventList(i).Description.  Is there a way to do this?  thank you.   

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Trend chart with events
« Reply #20 on: March 14, 2018, 03:20:23 PM »
One method is to apply a matrix to the graphics object, draw the text, then apply a new matrix so it clears the transforms.

Based in my sample project, the code would look like this:
Code: [Select]
                       '* Add a description string if it exists
                        If Not String.IsNullOrEmpty(m_EventList(i).Description) Then
                            Dim m As New System.Drawing.Drawing2D.Matrix()
                            m.RotateAt(30, New PointF(pos.X, pos.Y))
                            cg.Graphics.Transform = m
                            cg.Graphics.DrawString(m_EventList(i).Description, Me.Font, New SolidBrush(Color.Red), pos.X, pos.Y + Font.Height)
                            cg.Graphics.Transform = New Drawing2D.Matrix
                        End If

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: Trend chart with events
« Reply #21 on: March 16, 2018, 11:20:52 PM »
Works perfect Archie!  Can't thank you enough for the support.  Much appreciated!