Results 1 to 8 of 8

Thread: Chart with 3 Axis

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2015
    Posts
    68

    Chart with 3 Axis

    Hi, I need to have a chart with one X axis and two separate Y axis.

    I am measuring signal strength from a sensor, and phase, these will be measured at the same frequencies. I need to chart these real time.

    I currently have this working but with one Y axis and one X axis. It would be a lot cleaner (I think) if I could simply add another axis and link one of the data sets to that axis, and the other data set to the other axis.

    Is this possible?

    Thank you,

  2. #2
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: Chart with 3 Axis

    This example shows two chart areas using one chart control is that what you mean?

    There are other possibilities for two axis or series etc.

    This package has other ways to have mutilple things.

    Name:  a.png
Views: 887
Size:  21.1 KB

    Code:
    Imports System.Windows.Forms.DataVisualization.Charting
    
    Public Class Form3
        Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            'make the two areas y1, y2
            Chart1.ChartAreas.Clear()
            Chart1.ChartAreas.Add("Area1")
            Chart1.ChartAreas.Add("Area2")
    
            'make title
            Chart1.Titles.Add("Title 1")
            Chart1.Titles(0).Text = "Chart Title"
    
            'make the series
            Chart1.Series.Clear()
            Chart1.Series.Add("Series One")
            Chart1.Series.Add("Series Two")
            Chart1.Series.Add("Series Three")
    
            'assing series to chart area
            Chart1.Series("Series One").ChartArea = "Area1"
            Chart1.Series("Series Two").ChartArea = "Area2"
            Chart1.Series("Series Three").ChartArea = "Area2"
    
            'setup the chart area graphics
            With Chart1.ChartAreas("Area1")
                .AxisX.Title = "X axis"
                .AxisX.TitleFont = New Font("Times New Roman", 12, FontStyle.Bold)
                .AxisX.MajorGrid.LineColor = Color.LightBlue
                .AxisX.Interval = 2
                .AxisY.Title = "Y1 axis"
            End With
    
            With Chart1.ChartAreas("Area2")
                .AxisX.Title = "X axis"
                .AxisX.TitleFont = New Font("Times New Roman", 12, FontStyle.Bold)
                .AxisX.MajorGrid.LineColor = Color.LightBlue
                .AxisX.Interval = 2
                .AxisY.Title = "Y2 axis"
            End With
    
            With Chart1.Series(0)
                'define the series styles
                .ChartType = DataVisualization.Charting.SeriesChartType.Line
                .BorderWidth = 1
                .Color = Color.Red
                .BorderDashStyle = ChartDashStyle.Dash
                .MarkerStyle = DataVisualization.Charting.MarkerStyle.Square
                .MarkerSize = 4
                .Font = New Font("Arial", 9, FontStyle.Bold)
                .IsValueShownAsLabel = True                  'add point value labels to top of column
                .LabelFormat = "f0"                          'show label as one decimal place ie  XXX.X 
                .LabelForeColor = Color.Green             'point label color
            End With
    
            Chart1.Series(1).ChartType = DataVisualization.Charting.SeriesChartType.Line
            Chart1.Series(1).Color = Color.Blue
            Chart1.Series(2).ChartType = DataVisualization.Charting.SeriesChartType.Line
            Chart1.Series(2).Color = Color.Purple
            ' Chart1.Series(2).IsVisibleInLegend = False  'dont show this one in legend
    
            'add the data series
            For x = 1 To 9
                Chart1.Series(0).Points.AddXY(x, x - 1)
                Chart1.Series(1).Points.AddXY(x, 2 * x)
                Chart1.Series(2).Points.AddXY(x, 3 * x)
            Next
    
        End Sub
    End Class

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2015
    Posts
    68

    Re: Chart with 3 Axis

    Quote Originally Posted by tommytwotrain View Post
    This example shows two chart areas using one chart control is that what you mean?

    There are other possibilities for two axis or series etc.

    This package has other ways to have mutilple things.

    Name:  a.png
Views: 887
Size:  21.1 KB

    Code:
    Imports System.Windows.Forms.DataVisualization.Charting
    
    Public Class Form3
        Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            'make the two areas y1, y2
            Chart1.ChartAreas.Clear()
            Chart1.ChartAreas.Add("Area1")
            Chart1.ChartAreas.Add("Area2")
    
            'make title
            Chart1.Titles.Add("Title 1")
            Chart1.Titles(0).Text = "Chart Title"
    
            'make the series
            Chart1.Series.Clear()
            Chart1.Series.Add("Series One")
            Chart1.Series.Add("Series Two")
            Chart1.Series.Add("Series Three")
    
            'assing series to chart area
            Chart1.Series("Series One").ChartArea = "Area1"
            Chart1.Series("Series Two").ChartArea = "Area2"
            Chart1.Series("Series Three").ChartArea = "Area2"
    
            'setup the chart area graphics
            With Chart1.ChartAreas("Area1")
                .AxisX.Title = "X axis"
                .AxisX.TitleFont = New Font("Times New Roman", 12, FontStyle.Bold)
                .AxisX.MajorGrid.LineColor = Color.LightBlue
                .AxisX.Interval = 2
                .AxisY.Title = "Y1 axis"
            End With
    
            With Chart1.ChartAreas("Area2")
                .AxisX.Title = "X axis"
                .AxisX.TitleFont = New Font("Times New Roman", 12, FontStyle.Bold)
                .AxisX.MajorGrid.LineColor = Color.LightBlue
                .AxisX.Interval = 2
                .AxisY.Title = "Y2 axis"
            End With
    
            With Chart1.Series(0)
                'define the series styles
                .ChartType = DataVisualization.Charting.SeriesChartType.Line
                .BorderWidth = 1
                .Color = Color.Red
                .BorderDashStyle = ChartDashStyle.Dash
                .MarkerStyle = DataVisualization.Charting.MarkerStyle.Square
                .MarkerSize = 4
                .Font = New Font("Arial", 9, FontStyle.Bold)
                .IsValueShownAsLabel = True                  'add point value labels to top of column
                .LabelFormat = "f0"                          'show label as one decimal place ie  XXX.X 
                .LabelForeColor = Color.Green             'point label color
            End With
    
            Chart1.Series(1).ChartType = DataVisualization.Charting.SeriesChartType.Line
            Chart1.Series(1).Color = Color.Blue
            Chart1.Series(2).ChartType = DataVisualization.Charting.SeriesChartType.Line
            Chart1.Series(2).Color = Color.Purple
            ' Chart1.Series(2).IsVisibleInLegend = False  'dont show this one in legend
    
            'add the data series
            For x = 1 To 9
                Chart1.Series(0).Points.AddXY(x, x - 1)
                Chart1.Series(1).Points.AddXY(x, 2 * x)
                Chart1.Series(2).Points.AddXY(x, 3 * x)
            Next
    
        End Sub
    End Class







    Hi, thank you for you reply. What I actually mean is adding a third axis on the same graph. Is this possible in VB.NET?

    Thank you,

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,871

    Re: Chart with 3 Axis

    A lot of charting components have a secondary Y-axis.
    I'm not sure whether the chart component you are using support this.

    It seems it does:
    https://docs.microsoft.com/en-us/pre...9216(v=vs.140)
    https://stackoverflow.com/questions/...rol-two-y-axis

  5. #5
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: Chart with 3 Axis

    Now I suspect what is meant is 3 axis directions ie 3d coordinates x, y, z ?

    I believe the ms chart control does not support the "3d" graphics with 3 coordinate axes?

    Daniel, show an image or link to an example of exactly what you want to see if you are still interested.

    For ideas here is an isometric 3 axis xyz or 3d chart not sure what to call it? See the data points plotted with the green line in the example? The cube is just for effect.

    Name:  a.png
Views: 751
Size:  15.6 KB

    Code:
    '3d graph
    Public Class Form3
        Private Class Line3d
            Public pt1 As Point3d
            Public pt2 As Point3d
            Public color As Color
            Public width As Single
    
            Public Sub New(_color As Color, _width As Single, _pt1 As Point3d, _pt2 As Point3d)
                pt1 = _pt1
                pt2 = _pt2
                color = _color
                width = _width
            End Sub
        End Class
    
        Private Class Point3d
            Public x As Single
            Public y As Single
            Public z As Single
    
            Public Sub New(_x As Single, _y As Single, _z As Single)
                x = _x
                y = _y
                z = _z
            End Sub
        End Class
    
        Private Lines As New List(Of Line3d)
        Private GridAxisLines As New List(Of Line3d)
        Private Points As New List(Of Point3d)
        Private CosTheta As Double = Math.Cos(30 / 57.8)
        Private SinTheta As Double = Math.Sin(30 / 57.8)
    
        Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            BackColor = Color.White
            ResizeRedraw = True
            DoubleBuffered = True
            Text = "3d Graph"
    
            'x axis
            GridAxisLines.Add(New Line3d(Color.SkyBlue, 0.01, New Point3d(0, 0, 0), New Point3d(11, 0, 0)))
            ''y axis
            GridAxisLines.Add(New Line3d(Color.SkyBlue, 0.01, New Point3d(0, 11, 0), New Point3d(0, 0, 0)))
            ''z axis
            GridAxisLines.Add(New Line3d(Color.SkyBlue, 0.01, New Point3d(0, 0, 0), New Point3d(0, 0, 11)))
    
            'data points - plot connected with lines
            Points.Add(New Point3d(1, 3, 1))
            Points.Add(New Point3d(2, 5, 2))
            Points.Add(New Point3d(3, 3, 4))
            Points.Add(New Point3d(7, 7, 5))
    
            'cube frame
            'back face
            Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(1, 3, 1), New Point3d(7, 3, 1)))
            Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(1, 7, 1), New Point3d(7, 7, 1)))
            Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(1, 3, 1), New Point3d(1, 7, 1)))
            Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(7, 3, 1), New Point3d(7, 7, 1)))
            'front face
            Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(1, 3, 5), New Point3d(7, 3, 5)))
            Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(1, 7, 5), New Point3d(7, 7, 5)))
            Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(1, 3, 5), New Point3d(1, 7, 5)))
            Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(7, 3, 5), New Point3d(7, 7, 5)))
            'left side
            Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(1, 3, 1), New Point3d(1, 3, 5)))
            Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(1, 7, 1), New Point3d(1, 7, 5)))
            'right side
            Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(7, 3, 1), New Point3d(7, 3, 5)))
            Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(7, 7, 1), New Point3d(7, 7, 5)))
    
        End Sub
    
        Private Sub Form3_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
            With e.Graphics
                .ResetTransform()
                .SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
                Dim theScale As Double = 15
                Dim scaleRatio As Single = CSng(ClientSize.Width / theScale)
                .ScaleTransform(scaleRatio, scaleRatio)
                .TranslateTransform(1, 1)
    
                'draw grid
                Using f1 As New Font("arial", 0.5),
                        f2 As New Font("arial", 0.8, FontStyle.Italic)
                    For Each ln As Line3d In GridAxisLines
                        DrawLine3d(e.Graphics, ln)
                    Next
                    Dim x1, y1 As Single
                    For x As Integer = 0 To 10 Step 2
                        .DrawString(x.ToString, f1, Brushes.SkyBlue, x, 0)
                        .DrawString(x.ToString, f1, Brushes.SkyBlue, 0, x)
                        x1 = CSng(x * Math.Cos(30 / 57.8))
                        y1 = CSng(x * Math.Sin(30 / 57.8))
                        .DrawString(x.ToString, f1, Brushes.SkyBlue, x1, y1)
                    Next
                    .DrawString("X", f2, Brushes.Black, 11, 0.5)
                    .DrawString("Y", f2, Brushes.Black, 0.5, 11)
                    .DrawString("Z", f2, Brushes.Black, CSng(11 * Math.Cos(30 / 57.8)), CSng(11 * Math.Sin(30 / 57.8)))
                End Using
            End With
    
            'draw the list of line objects that make cube
            For Each ln As Line3d In Lines
                DrawLine3d(e.Graphics, ln)
            Next
    
            'graph points connected with line
            For i As Integer = 0 To Points.Count - 2
                DrawLine3d(e.Graphics, New Line3d(Color.Green, 0.2, Points(i), Points(i + 1)))
                DrawPoint3d(e.Graphics, Points(i + 1))
            Next
            DrawPoint3d(e.Graphics, Points(0))
    
        End Sub
    
        Private Sub DrawPoint3d(g As Graphics, pt1 As Point3d)
            With g
                Using p As New Pen(Color.Lime, 0.1)
                    Dim r As Single = 0.4
                    .DrawEllipse(p, New RectangleF(CSng(pt1.x + (pt1.z * CosTheta)) - (r / 2),
                                 CSng(pt1.y + (pt1.z * SinTheta)) - (r / 2), r, r))
                End Using
            End With
        End Sub
    
        Private Sub DrawLine3d(g As Graphics, line1 As Line3d)
            With g
                Using p As New Pen(line1.color, line1.width)
                    .DrawLine(p,
                          New PointF(CSng(line1.pt1.x + (line1.pt1.z * CosTheta)),
                                     CSng(line1.pt1.y + (line1.pt1.z * SinTheta))),
                          New PointF(CSng(line1.pt2.x + (line1.pt2.z * CosTheta)),
                                     CSng(line1.pt2.y + (line1.pt2.z * SinTheta))))
                End Using
            End With
        End Sub
    End Class
    Last edited by tommytwotrain; Sep 2nd, 2019 at 06:03 PM.

  6. #6
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Chart with 3 Axis

    Well, he said two Y axis, not a 3rd dimension (i.e. Z axis).

  7. #7
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,757

    Re: Chart with 3 Axis

    Quote Originally Posted by DanielB33 View Post
    Hi, I need to have a chart with one X axis and two separate Y axis.
    Set the second Series' YAxis to the chart area's Secondary axis.
    Name:  Capture.jpg
Views: 753
Size:  20.5 KB
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Nov 2015
    Posts
    68

    Re: Chart with 3 Axis

    That did it! Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width