折线趋势图的实现方法

zhaoxichao 2008-01-30 03:07:59
VB.net2005里面怎么实现折线趋势图,一组整数的数组
...全文
547 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
linton 2008-07-07
  • 打赏
  • 举报
回复
不错,值得学习学习。
于之 2008-04-09
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 limx001 的回复:]
to : taiji1982
你这段代码运行没有错,不过,没有结果出来,怎么回事呢?
[/Quote]

再顶一下!
es021 2008-04-08
  • 打赏
  • 举报
回复
zedgraph控件也不错 推荐一下
于之 2008-04-08
  • 打赏
  • 举报
回复
to : taiji1982
你这段代码运行没有错,不过,没有结果出来,怎么回事呢?
永恒挑战 2008-04-08
  • 打赏
  • 举报
回复
Dim G As Graphics ' = PictureBox1.CreateGraphics()
Dim bmp As New Bitmap(PictureBox1.Width, PictureBox1.Height)
G = Graphics.FromImage(bmp)
Dim P As New Pen(Color.Green, 2)
G.DrawLine(P, 0, 300, 733, 300)
G.DrawLine(P, 600, 0, 600, 349)
G.DrawLine(P, 0, 300, 5, 297)
G.DrawLine(P, 0, 300, 5, 303)
G.DrawLine(P, 600, 0, 597, 5)
G.DrawLine(P, 600, 0, 603, 5)
P.Width = 1
Dim i As Long
Dim W As Long = 30
For i = 1 To 19
G.DrawLine(P, 600 - W * i, 0, 600 - W * i, 300)
Next
For i = 1 To 28
G.DrawLine(P, 0, 300 - 10 * i, 600, 300 - 10 * i)
If i Mod 5 = 0 Then
G.DrawString(i * 10, New Font("宋体", 9), Brushes.Red, 605, 300 - i * 10 - 4)
G.DrawString(i, New Font("宋体", 9), Brushes.Cyan, 640, 300 - i * 10 - 4)
G.DrawString(i * 4, New Font("宋体", 9), Brushes.Yellow, 675, 300 - i * 10 - 4)

End If
Next
G.DrawString("0", New Font("宋体", 9), Brushes.White, 605, 305)
G.DrawString("时间", New Font("宋体", 9), Brushes.White, 5, 305)
G.DrawString("电压(V)", New Font("宋体", 9), Brushes.Red, 605, 5)
G.DrawString("电流(A)", New Font("宋体", 9), Brushes.Cyan, 623, 19)
G.DrawString("功率(KW)", New Font("宋体", 9), Brushes.Yellow, 655, 32)

于之 2008-04-08
  • 打赏
  • 举报
回复
TO: Caofusheng

你的代码提示要声明,到底要声明哪些呢? 比如: g.SmoothingMode = SmoothingMode.AntiAlias
提示smoothingMode 未声明,要如何声明呢? 请指点,谢谢!
shclhs 2008-01-31
  • 打赏
  • 举报
回复
up
caofusheng 2008-01-30
  • 打赏
  • 举报
回复
MSChart控件可以动态的画图表,挺好用的。
zhaoxichao 2008-01-30
  • 打赏
  • 举报
回复
谢谢各位,有没有控件来做这个,我这个趋势图比较复杂,XY轴都随时要变化
caofusheng 2008-01-30
  • 打赏
  • 举报
回复
使用方法

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
createBG() '画饼图
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
createZG() '画柱状图
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
createZXG() '画折线图
End Sub

xiaojing7 2008-01-30
  • 打赏
  • 举报
回复
up
caofusheng 2008-01-30
  • 打赏
  • 举报
回复
以上是绘制饼图,柱状图和折线图的例子
caofusheng 2008-01-30
  • 打赏
  • 举报
回复
你看看这个对你有没有用


Sub createBG() '绘制饼图
Dim height As Integer = 200
Dim width As Integer = 200
Dim bmp As New Bitmap(width, height)
Dim g As Graphics = Graphics.FromImage(bmp)
Dim pen As Pen = New Pen(Color.Black)

Dim outline As Rectangle = New Rectangle(0, 0, height - 5, width - 5)

g.SmoothingMode = SmoothingMode.AntiAlias
g.Clear(Color.White)

'绘制饼图
'绘制一个由边框(该边框由一对坐标、高度和宽度指定)定义的椭圆
g.DrawEllipse(pen, outline)
'填充由一对坐标、一个宽度、一个高度以及两条射线指定的椭圆所定义的扇形区的内部
'关键在第二,三个参数:从x轴到扇形边1的度数;从扇形边1到边2的读书,下面绘制了各占90度的图
'g.FillPie(New SolidBrush(Color.Red), outline, -20.0F, 90.0F)
'g.FillPie(New SolidBrush(Color.Yellow), outline, 70.0F, 150.0F)
'g.FillPie(New SolidBrush(Color.Blue), outline, 220.0F, 100.0F)
'g.FillPie(New SolidBrush(Color.Green), outline, 320.0F, 20.0F)
g.FillPie(New SolidBrush(Color.Red), outline, 0.0F, 90.0F)
g.FillPie(New SolidBrush(Color.Yellow), outline, 90.0F, 90.0F)
g.FillPie(New SolidBrush(Color.Blue), outline, 180.0F, 90.0F)
g.FillPie(New SolidBrush(Color.Green), outline, 270.0F, 90.0F)

bmp.Save(Page.Response.OutputStream, ImageFormat.Jpeg)

g.Dispose()
bmp.Dispose()
End Sub
Sub createZG()
Dim height As Integer = 200
Dim width As Integer = 200
Dim space As Integer = 20 '原点到左边和下边的距离
Dim interval As Integer = 20 '单位长度
Dim max_x As Integer = 8 'x轴最大刻度
Dim max_y As Integer = 8
Dim bmp As New Bitmap(width, height)
Dim g As Graphics = Graphics.FromImage(bmp)
Dim pen As Pen = New Pen(Color.Black, 1)
Dim pen_chart As Pen = New Pen(Color.Blue, 12)

'定义一组数据
Dim arrData() As Double = {5.21, 3.34, 2.5, 7.65, 6.54, 1.2, 2.32, 6.48}
Dim i As Integer

g.SmoothingMode = SmoothingMode.AntiAlias
g.Clear(Color.White)

'g.DrawLine(pen,point1,point2)
'Pen 对象,它确定线条的颜色、宽度和样式。
'Point 结构,它表示要连接的第一个点。
'Point 结构,它表示要连接的第二个点。
g.DrawLine(pen, New Point(space, height - space), New Point(width, height - space)) 'x轴
g.DrawLine(pen, New Point(space, 0), New Point(space, height - space)) 'y轴

'x轴上的刻度
For i = 0 To width - interval Step interval
If i <= max_x * interval Then
'g.DrawString(string,Font,Brush,PointF)
'String对象,要绘制的字符串。
'Font 对象,它定义字符串的文本格式。
'Brush 对象,它确定所绘制文本的颜色和纹理。
'PointF 结构,它指定所绘制文本的左上角。
'可以单独先定义变量drawString, drawFont, drawBrush, drawPoint
g.DrawString(i / interval, New Font("Arail", 9, FontStyle.Regular), SystemBrushes.WindowText, New PointF(space + i - 5, height - space))
End If
Next

'y轴上的刻度
For i = 0 To height - interval Step interval
If i <= max_y * interval Then
g.DrawLine(pen, New Point(space, height - i - space), New Point(space + 5, height - i - space))

If i <> 0 Then
g.DrawString(i / interval, New Font("Arial", 9, FontStyle.Regular), SystemBrushes.WindowText, New PointF(space - 12, height - space - i - 6))
End If
End If
Next

'柱形图
For i = 0 To UBound(arrData)
g.DrawLine(pen_chart, New Point(space + (i + 1) * interval, height - space - arrData(i) * interval), New Point(space + (i + 1) * interval, height - space))

Next

'输出结果
bmp.Save(Response.OutputStream, ImageFormat.Jpeg)

g.Dispose()
bmp.Dispose()
End Sub
Sub createZXG()
Dim height As Integer = 200
Dim width As Integer = 200
Dim space As Integer = 20 '原点到左边和下边的距离
Dim interval As Integer = 20 '单位长度
Dim max_x As Integer = 8 'x轴最大刻度
Dim max_y As Integer = 8
Dim bmp As New Bitmap(width, height)
Dim g As Graphics = Graphics.FromImage(bmp)
Dim pen As Pen = New Pen(Color.Black, 1)
Dim pen_chart As Pen = New Pen(Color.Blue, 2) '在此处设置折线宽度和颜色

'定义一组数据
Dim arrData() As Double = {5.21, 3.34, 2.5, 7.65, 6.54, 1.2, 2.32, 6.48}
Dim i As Integer

g.SmoothingMode = SmoothingMode.AntiAlias
g.Clear(Color.White)

'g.DrawLine(pen,point1,point2)
'Pen 对象,它确定线条的颜色、宽度和样式。
'Point 结构,它表示要连接的第一个点。
'Point 结构,它表示要连接的第二个点。
g.DrawLine(pen, New Point(space, height - space), New Point(width, height - space)) 'x轴
g.DrawLine(pen, New Point(space, 0), New Point(space, height - space)) 'y轴

'x轴上的刻度
For i = 0 To width - interval Step interval
If i <= max_x * interval Then
'g.DrawString(string,Font,Brush,PointF)
'String对象,要绘制的字符串。
'Font 对象,它定义字符串的文本格式。
'Brush 对象,它确定所绘制文本的颜色和纹理。
'PointF 结构,它指定所绘制文本的左上角。
'可以单独先定义变量drawString, drawFont, drawBrush, drawPoint
g.DrawString(i / interval, New Font("Arail", 9, FontStyle.Regular), SystemBrushes.WindowText, New PointF(space + i - 5, height - space))
End If
Next

'y轴上的刻度
For i = 0 To height - interval Step interval
If i <= max_y * interval Then
g.DrawLine(pen, New Point(space, height - i - space), New Point(space + 5, height - i - space))

If i <> 0 Then
g.DrawString(i / interval, New Font("Arial", 9, FontStyle.Regular), SystemBrushes.WindowText, New PointF(space - 12, height - space - i - 6))
End If
End If
Next
'-----------------------------------以上同画柱状图---------------------------------------------
'画折线图
For i = 0 To UBound(arrData) - 1
g.DrawLine(pen_chart, New Point(space + i * interval, height - space - arrData(i) * interval), New Point(space + (i + 1) * interval, height - space - arrData(i + 1) * interval))
'g.DrawLine(pen_chart, New Point(space + (i + 1) * interval, height - space - arrData(i) * interval), New Point(space + (i + 1) * interval, height - space))
Next

bmp.Save(Response.OutputStream, ImageFormat.Jpeg)

g.Dispose()
bmp.Dispose()

End Sub

llsus 2008-01-30
  • 打赏
  • 举报
回复
给你一段我曾经画电流电压曲线图的代码,你参考下

Dim G As Graphics ' = PictureBox1.CreateGraphics()
Dim bmp As New Bitmap(PictureBox1.Width, PictureBox1.Height)
G = Graphics.FromImage(bmp)
Dim P As New Pen(Color.Green, 2)
G.DrawLine(P, 0, 300, 733, 300)
G.DrawLine(P, 600, 0, 600, 349)
G.DrawLine(P, 0, 300, 5, 297)
G.DrawLine(P, 0, 300, 5, 303)
G.DrawLine(P, 600, 0, 597, 5)
G.DrawLine(P, 600, 0, 603, 5)
P.Width = 1
Dim i As Long
Dim W As Long = 30
For i = 1 To 19
G.DrawLine(P, 600 - W * i, 0, 600 - W * i, 300)
Next
For i = 1 To 28
G.DrawLine(P, 0, 300 - 10 * i, 600, 300 - 10 * i)
If i Mod 5 = 0 Then
G.DrawString(i * 10, New Font("宋体", 9), Brushes.Red, 605, 300 - i * 10 - 4)
G.DrawString(i, New Font("宋体", 9), Brushes.Cyan, 640, 300 - i * 10 - 4)
G.DrawString(i * 4, New Font("宋体", 9), Brushes.Yellow, 675, 300 - i * 10 - 4)

End If
Next
G.DrawString("0", New Font("宋体", 9), Brushes.White, 605, 305)
G.DrawString("时间", New Font("宋体", 9), Brushes.White, 5, 305)
G.DrawString("电压(V)", New Font("宋体", 9), Brushes.Red, 605, 5)
G.DrawString("电流(A)", New Font("宋体", 9), Brushes.Cyan, 623, 19)
G.DrawString("功率(KW)", New Font("宋体", 9), Brushes.Yellow, 655, 32)


For i = 0 To 19
P.Color = Color.Red
G.DrawLine(P, 600 - i * W, 300 - CSng(DY(i)) / 100, 600 - (i + 1) * W, 300 - CSng(DY(i + 1) / 100))

Next
PictureBox1.Image = bmp

16,721

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧