如何在vb.net中的图形或条形图中使用DateTime轴? [英] How to use DateTime axes in graph or bar chart in vb.net?
问题描述
我想使用y轴作为日期时间,使用x轴作为整数。我使用zedgraph控件。
i使用以下代码
< pre lang =vb> Imports ZedGraph
公共 类 Form6
Dim frames as 整数
Dim time1 As TimeSpan()
公开 Sub 新( ByVal no_frame 作为 整数, ByVal time() As TimeSpan)
InitializeComponent()
frames = no_frame
time1 = time
结束 Sub
私有 Sub Form2_Load( ByVal 发件人作为系统。对象, ByVal e As System.EventArgs)句柄 MyBase .Load
CreateGraph(ZedGraphControl1)
SetSize()
End Sub
私有 Sub CreateGraph( ByVal zgc As ZedGraphControl)
Dim myPane 作为 GraphPane = zgc.GraphPane
myPane.Title.Text = 浪费停止和等待协议中的带宽
myPane.XAxis.Title.Text = 否框架
myPane.YAxis.Title.Text = 时间
myPane.YAxis.Type = AxisType。日期
' 从正弦函数中构成一些数据点
Dim list = 新的 PointPairList()
Dim x As 整数
Dim y( 100 ) As TimeSpan
对于 x = 1 帧
y(x)= time1(x)
list.Add(x,y(x))
下一步 x
' 生成带圆圈符号的蓝色曲线,图例中的我的曲线2
Dim myCurve As LineItem = myPane.AddCurve( My Curve,list,Color.Blue,SymbolType.Circle)
' 使用45度的白红色渐变填充曲线下方的区域
myCurve.Line.Fill = 新填充(Color.White,Color.Red, 45 .0F)
' 通过填充白色来使符号不透明
myCurve.Symbol.Fill = 新填充(颜色。白色)
' 使用颜色渐变
myPane.Chart填充轴背景。 Fill = 新填充(Color.White,Color.LightGoldenrodYellow, 45 .0F)
< span class =code-comment>' 使用颜色渐变填充窗格背景
myPane.Fill = 新填充(Color.White,Color.FromArgb( 220 , 220 , 255 ), 45 .0F)
' 计算轴比例范围
zgc.AxisChange()
结束 Sub
私有 Sub Form1_Resize( ByVal sender As System。 Object , ByVal e As System.EventArgs)句柄 MyBase .Resize
SetSize()
结束 Sub
私有 Sub SetSize()
ZedGraphControl1.Location = 新点( 10 , 10 )
< span class =code-comment>' 在控件外围留一个小边距
ZedGraphControl1.Size = 新大小(ClientRectangle.Width - 20 ,ClientRectangle.Height - 20 )
结束 Sub
结束 < span class =code-keyword> Class
以上代码错误
Public Sub Add(x As Double(),y As Double())':
参数匹配参数'x'无法从'Integer'转换为'Double()'。
参数匹配参数'y'无法从'TimeSpan转换'到'Double()'。
'公开覆盖子添加(x为双倍,为双倍)':
参数匹配参数'y'无法从'TimeSpan'转换为'Double'。
这是什么解决方案?
我解决了
< pre lang = vb>
导入ZedGraph
公共类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作为ZedGraphControl)
Dim myPane As GraphPane = zgc.GraphPane
myPane.Title.Text =停止和等待协议中的带宽浪费
m yPane.XAxis.Title.Text =No of Frames
myPane.YAxis.Title.Text =Time
'myPane.YAxis.Type = AxisType.Date
'myPane.YAxis .Scale.Format =HH:mm:ss:fff
'从正弦函数构成一些数据点
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))
下一个x
'生成带圆圈符号的蓝色曲线,并在图例中生成My Curve 2
Dim myCurve As LineItem = myPane.AddCurve( My Curve,list,Color.Blue,SymbolType.Circle)
'用45度白红色渐变填充曲线下面积
myCurve.Line.Fill = New Fill(Color.White) ,Color.Red,45.0F)
'通过填充白色来使符号变得不透明
myCurve.Symbol.Fill = New Fill(Color.White)
'用轴填充轴背景颜色渐变
myPane.Chart.Fill = New Fill(Color.White,Color.LightGoldenrodYellow,45.0F)
'用颜色渐变填充窗格背景
myPane.Fill = New Fill(Color.White ,Color.FromArgb(220,220,255),45.0F)
'计算轴刻度范围
zgc.AxisChange()
结束次级
私有子Form1_Resize(ByVal发送者) As System.Object,ByVal e As System.EventArgs)Handles MyBase.Resize
SetSize()
End Sub
Private Sub SetSize()
ZedGraphControl1.Location = New Point(10 ,10)
'在控件外围留一小幅度
ZedGraphControl1.Size =新尺寸(ClientRectangle.Width - 20,ClientRectangle.Height - 20)
End Sub
结束班
i want to use y axes as datetime and x axes as interger. i used zedgraph control.
i used the following code
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
error for the above code
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'.
what is the solution for this ?
i solved
<pre lang="vb">
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
End Class
这篇关于如何在vb.net中的图形或条形图中使用DateTime轴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!