Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim str As String = " SELECT date,h2 FROM History_sp"
Dim CountText As String = "SELECT COUNT(*) From History_sp" Dim conn1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\spdb.mdb;" & _
"User ID=Admin;" & _
"Password="
Dim conn As OleDbConnection = New OleDbConnection(conn1)
conn.Open()
Dim mycommand As OleDbCommand = New OleDbCommand(str, conn)
Dim myCount As OleDbCommand = New OleDbCommand(CountText, conn)
Dim i, NumPoints As Integer
NumPoints = myCount.ExecuteScalar
conn.Close()
conn.Open()
Dim myOleDbDataReader As OleDbDataReader
myOleDbDataReader = mycommand.ExecuteReader()
Dim ax(NumPoints - 1)
Dim ay(NumPoints - 1)
While myOleDbDataReader.Read
ax(i) = myOleDbDataReader.GetValue(1)
ay(i) = myOleDbDataReader.GetValue(0)
i = i + 1
End While
conn.Close()
'声明整型变量i,
'创建一个位图对象,用来放置柱形图,我们可以把它看作是一块画布。
'这里宽、高分别是400和200,当然,你也可以根据需要把它们做为参数来进行传递。
Dim objBitMap As New Bitmap(400, 200) '声明一个图形对象,在上面创建的位图上画图。
Dim objGraphics As Graphics '从指定的objBitMap对象创建新图形对象objGraphics。
objGraphics = Graphics.FromImage(objBitMap) '清除整个绘图面并以指定白色为背景色进行填充。
objGraphics.Clear(Color.White) '创建一个数据源,这里我们为了方便其间,采用数组做为柱形图和饼图的数据源。
'在画布(objBitMap对象)的坐标5,5处,用指定的Brush(画笔)对象和Font(字体)对象绘制统计图标题。
objGraphics.DrawString(" X 公司上半年销售情况", _
New Font("宋体", 16), Brushes.Black, New PointF(5, 5)) '创建图例文字。
Dim symbolLeg As PointF = New PointF(335, 20)
Dim descLeg As PointF = New PointF(360, 16) '画出图例。利用objGraphics图形对象的三个方法画出图例:
'FillRectangle()方法画出填充矩形,DrawRectangle()方法画出矩形的边框,
'DrawString()方法画出说明文字。这三个图形对象的方法在 .NET 框架类库类库中均已重载,
'可以很方便根据不同的参数来画出图形。
For i = 0 To ax.Length - 1 '画出填充矩形。
objGraphics.FillRectangle(New SolidBrush(GetColor(i)), symbolLeg.X, symbolLeg.Y, 20, 10) '画出矩形边框。
objGraphics.DrawRectangle(Pens.Black, symbolLeg.X, symbolLeg.Y, 20, 10) '画出图例说明文字。
objGraphics.DrawString(ax(i).ToString, New Font("宋体", 10), Brushes.Black, descLeg) '移动坐标位置,只移动Y方向的值即可。
symbolLeg.Y += 15
descLeg.Y += 15 Next i For i = 0 To NumPoints - 1
Dim pen1 As Pen = New Pen(Color.Blue)
Dim point1 As New Point(Val(ax(i)), Val(ay(i)))
Dim point2 As New Point(Val(ax(i + 1)), Val(ay(i + 1))) objGraphics.DrawLine(pen1, point1, point2)
Next '将objGraphics对象以指定的图形格式(这里是Gif)保存到指定的Stream对象,并输出到客户端。
objBitMap.Save(Response.OutputStream, ImageFormat.Gif) End Sub
draw.line函数的各个参数要求是point类型或single,而我想画的是日期趋势图,这里面的日期怎么处
Dim str As String = " SELECT date,h2 FROM History_sp"
Dim CountText As String = "SELECT COUNT(*) From History_sp" Dim conn1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\spdb.mdb;" & _
"User ID=Admin;" & _
"Password="
Dim conn As OleDbConnection = New OleDbConnection(conn1)
conn.Open()
Dim mycommand As OleDbCommand = New OleDbCommand(str, conn)
Dim myCount As OleDbCommand = New OleDbCommand(CountText, conn)
Dim i, NumPoints As Integer
NumPoints = myCount.ExecuteScalar
conn.Close()
conn.Open()
Dim myOleDbDataReader As OleDbDataReader
myOleDbDataReader = mycommand.ExecuteReader()
Dim ax(NumPoints - 1)
Dim ay(NumPoints - 1)
While myOleDbDataReader.Read
ax(i) = myOleDbDataReader.GetValue(1)
ay(i) = myOleDbDataReader.GetValue(0)
i = i + 1
End While
conn.Close()
'声明整型变量i,
'创建一个位图对象,用来放置柱形图,我们可以把它看作是一块画布。
'这里宽、高分别是400和200,当然,你也可以根据需要把它们做为参数来进行传递。
Dim objBitMap As New Bitmap(400, 200) '声明一个图形对象,在上面创建的位图上画图。
Dim objGraphics As Graphics '从指定的objBitMap对象创建新图形对象objGraphics。
objGraphics = Graphics.FromImage(objBitMap) '清除整个绘图面并以指定白色为背景色进行填充。
objGraphics.Clear(Color.White) '创建一个数据源,这里我们为了方便其间,采用数组做为柱形图和饼图的数据源。
'在画布(objBitMap对象)的坐标5,5处,用指定的Brush(画笔)对象和Font(字体)对象绘制统计图标题。
objGraphics.DrawString(" X 公司上半年销售情况", _
New Font("宋体", 16), Brushes.Black, New PointF(5, 5)) '创建图例文字。
Dim symbolLeg As PointF = New PointF(335, 20)
Dim descLeg As PointF = New PointF(360, 16) '画出图例。利用objGraphics图形对象的三个方法画出图例:
'FillRectangle()方法画出填充矩形,DrawRectangle()方法画出矩形的边框,
'DrawString()方法画出说明文字。这三个图形对象的方法在 .NET 框架类库类库中均已重载,
'可以很方便根据不同的参数来画出图形。
For i = 0 To ax.Length - 1 '画出填充矩形。
objGraphics.FillRectangle(New SolidBrush(GetColor(i)), symbolLeg.X, symbolLeg.Y, 20, 10) '画出矩形边框。
objGraphics.DrawRectangle(Pens.Black, symbolLeg.X, symbolLeg.Y, 20, 10) '画出图例说明文字。
objGraphics.DrawString(ax(i).ToString, New Font("宋体", 10), Brushes.Black, descLeg) '移动坐标位置,只移动Y方向的值即可。
symbolLeg.Y += 15
descLeg.Y += 15 Next i For i = 0 To NumPoints - 1
Dim pen1 As Pen = New Pen(Color.Blue)
Dim point1 As New Point(Val(ax(i)), Val(ay(i)))
Dim point2 As New Point(Val(ax(i + 1)), Val(ay(i + 1))) objGraphics.DrawLine(pen1, point1, point2)
Next '将objGraphics对象以指定的图形格式(这里是Gif)保存到指定的Stream对象,并输出到客户端。
objBitMap.Save(Response.OutputStream, ImageFormat.Gif) End Sub
draw.line函数的各个参数要求是point类型或single,而我想画的是日期趋势图,这里面的日期怎么处
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货