如何在vb.net中使用条形图中的时间轴?

时间:2015-04-07 02:59:52

标签: vb.net

我想使用y轴作为时间跨度,使用x轴作为整数。我使用了zedgraph控件。

  Imports ZedGraph
 Public Class Form6
Dim frames As Integer
Dim time1 As TimeSpan()
Public Sub New(ByVal no_frame As Integer, ByVal time() As TimeSpan)
    InitializeComponent()
    frames = no_frame
    time1 = time
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    CreateGraph(ZedGraphControl1)
    SetSize()
End Sub
Private Sub CreateGraph(ByVal zgc As ZedGraphControl)
    Dim myPane As GraphPane = zgc.GraphPane
    myPane.Title.Text = "Waste of Bandwidth in Stop and Wait Protocol"
    myPane.XAxis.Title.Text = "No of Frames"
    myPane.YAxis.Title.Text = "Time"
    myPane.YAxis.Type = AxisType.Date
    ' Make up some data points from the Sine function
    Dim list = New PointPairList()
    Dim x As Integer
    Dim y(100) As TimeSpan
    For x = 1 To frames
        y(x) = time1(x)
        list.Add(x, y(x))
    Next x
    ' Generate a blue curve with circle symbols, and "My Curve 2" in the legend
    Dim myCurve As LineItem = myPane.AddCurve("My Curve", list, Color.Blue, SymbolType.Circle)
    ' Fill the area under the curve with a white-red gradient at 45 degrees
    myCurve.Line.Fill = New Fill(Color.White, Color.Red, 45.0F)
    ' Make the symbols opaque by filling them with white
    myCurve.Symbol.Fill = New Fill(Color.White)
    ' Fill the axis background with a color gradient
    myPane.Chart.Fill = New Fill(Color.White, Color.LightGoldenrodYellow, 45.0F)
    ' Fill the pane background with a color gradient
    myPane.Fill = New Fill(Color.White, Color.FromArgb(220, 220, 255), 45.0F)
    ' Calculate the Axis Scale Ranges
    zgc.AxisChange()
End Sub
Private Sub Form1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
    SetSize()
End Sub
Private Sub SetSize()
    ZedGraphControl1.Location = New Point(10, 10)
    ' Leave a small margin around the outside of the control
    ZedGraphControl1.Size = New Size(ClientRectangle.Width - 20, ClientRectangle.Height - 20)
End Sub
  End Class
上述代码的

错误

    Public Sub Add(x As Double(), y As Double())':

Argument matching parameter 'x' cannot convert from 'Integer' to 'Double()'.

Argument matching parameter 'y' cannot convert from 'TimeSpan' to 'Double()'.

'Public Overrides Sub Add(x As Double, y As Double)':

Argument matching parameter 'y' cannot convert from 'TimeSpan' to 'Double'. 

这是什么解决方案? 在vb.net中还有其他图形或条形图控件吗?如果是,那么如何在vb.net中使用条形图来表示时间轴? (整数)应为x轴,(Timespan)应为y轴。请帮帮我。

1 个答案:

答案 0 :(得分:0)

我自己解决了......谢谢你们......

 Imports ZedGraph
  Public Class Form6
  Dim frames As Integer
  Dim time1 As TimeSpan()
Dim str As String
Public Sub New(ByVal no_frame As Integer, ByVal time() As TimeSpan)
    InitializeComponent()
    frames = no_frame
    time1 = time
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    CreateGraph(ZedGraphControl1)
    SetSize()
End Sub

Private Sub CreateGraph(ByVal zgc As ZedGraphControl)
    Dim myPane As GraphPane = zgc.GraphPane
    myPane.Title.Text = "Waste of Bandwidth in Stop and Wait Protocol"
    myPane.XAxis.Title.Text = "No of Frames"
    myPane.YAxis.Title.Text = "Time"
    'myPane.YAxis.Type = AxisType.Date
    'myPane.YAxis.Scale.Format = "HH:mm:ss:fff"

    ' Make up some data points from the Sine function
    Dim list = New PointPairList()
    Dim x As Double
    Dim y(100) As Double
    For x = 1 To frames
        y(x) = (Convert.ToDouble(time1(x).TotalSeconds))
        list.Add(x, y(x))
    Next x
    ' Generate a blue curve with circle symbols, and "My Curve 2" in the legend
    Dim myCurve As LineItem = myPane.AddCurve("My Curve", list, Color.Blue, SymbolType.Circle)
    ' Fill the area under the curve with a white-red gradient at 45 degrees
    myCurve.Line.Fill = New Fill(Color.White, Color.Red, 45.0F)
    ' Make the symbols opaque by filling them with white
    myCurve.Symbol.Fill = New Fill(Color.White)
    ' Fill the axis background with a color gradient
    myPane.Chart.Fill = New Fill(Color.White, Color.LightGoldenrodYellow, 45.0F)
    ' Fill the pane background with a color gradient
    myPane.Fill = New Fill(Color.White, Color.FromArgb(220, 220, 255), 45.0F)
    ' Calculate the Axis Scale Ranges
    zgc.AxisChange()
End Sub
Private Sub Form1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
    SetSize()
End Sub
Private Sub SetSize()
    ZedGraphControl1.Location = New Point(10, 10)
    ' Leave a small margin around the outside of the control
    ZedGraphControl1.Size = New Size(ClientRectangle.Width - 20, ClientRectangle.Height - 20)
End Sub

结束班