如何显示我的折线图?

时间:2014-07-09 14:55:34

标签: vb.net graph charts

我正在尝试以编程方式让我的Chart对象出现。我已经能够使用Design文件显示图表,但是对于我正在做的事情,我需要了解Chart Control如何以编程方式工作。

这是我的代码:

    Dim wavesGraph As New Chart()

    Dim chartarea As New ChartArea

    Dim vn1Series As New Series("VN1", SeriesChartType.Line)
    Dim vn2Series As New Series("VN2", SeriesChartType.Line)
    Dim vn3Series As New Series("VN3", SeriesChartType.Line)
    Dim vdi1Series As New Series("VDI1", SeriesChartType.Line)
    Dim vdi2Series As New Series("VDI2", SeriesChartType.Line)
    Dim vdi3Series As New Series("VDI3", SeriesChartType.Line)


    wavesGraph.ChartAreas.Add(chartarea)

    wavesGraph.Series.Add(vn1Series)
    wavesGraph.Series.Add(vn2Series)
    wavesGraph.Series.Add(vn3Series)
    wavesGraph.Series.Add(vdi1Series)
    wavesGraph.Series.Add(vdi2Series)
    wavesGraph.Series.Add(vdi3Series)

    Console.WriteLine("Here1")
    wavesGraph.ChartAreas(0).Visible = True


    wavesGraph.ChartAreas(0).AxisY2.Enabled = AxisEnabled.True
    wavesGraph.ChartAreas(0).AxisY.Title = "Network Voltage"
    If (WavesIsI) Then

        wavesGraph.ChartAreas(0).AxisY2.Title = "Network Current"
    Else
        wavesGraph.ChartAreas(0).AxisY2.Title = "Differential Volts"
    End If
    wavesGraph.Series("VDI1").YAxisType = AxisType.Secondary
    wavesGraph.Series("VDI2").YAxisType = AxisType.Secondary
    wavesGraph.Series("VDI3").YAxisType = AxisType.Secondary


    Dim rand As New Random
    Console.WriteLine("Here2")

    For i As Integer = 0 To 166

        wavesGraph.Series(0).Points.AddXY(i, rand.Next(-255, 255))
        'wavesGraph.Series(1).Points.AddXY(i, rand.Next(-255, 255))
        'wavesGraph.Series(2).Points.AddXY(i, rand.Next(-255, 255))
        wavesGraph.Series(3).Points.AddXY(i, rand.Next(-255, 255))
        'wavesGraph.Series(4).Points.AddXY(i, rand.Next(-255, 255))
        'wavesGraph.Series(5).Points.AddXY(i, rand.Next(-255, 255))
    Next
    wavesGraph.Enabled = True
    wavesGraph.Visible = True
    Console.WriteLine("Here3")

这是我得到的线图: enter image description here

1 个答案:

答案 0 :(得分:1)

我复制了您的代码1:1并在最后添加了Me.Controls.Add(wavesGraph)以将图表添加到表单中。

您没有以任何方式将控件添加到表单中,因此新创建的图表永远不会显示。