asp.net画趋势图的问题

lqwsky 2006-08-04 09:51:24
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim str As String = " SELECT date,h2,co 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)
Dim az(NumPoints - 1)
While myOleDbDataReader.Read
ax(i) = i
ay(i) = myOleDbDataReader.GetValue(1)
az(i) = myOleDbDataReader.GetValue(2)
i = i + 1
End While
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

Dim Opoint As New Point(100, 100)
Dim pen1 As Pen = New Pen(Color.Black)
Dim pointXx As New Point(100, 100)
Dim pointXy As New Point(200, 100)
Dim pointYy As New Point(100, 50)
objGraphics.DrawLine(pen1, pointXx, pointXy)
objGraphics.DrawLine(pen1, pointXx, pointYy)
For i = 0 To NumPoints - 2
Dim pen As Pen = New Pen(Color.Blue)
Dim point1 As New Point(Val(ax(i)) + 100, 100 - Val(ay(i)))
Dim point2 As New Point(Val(ax(i + 1)) + 100, 100 - Val(ay(i + 1)))

objGraphics.DrawLine(pen, point1, point2)
Next

For i = 0 To NumPoints - 2
Dim pen As Pen = New Pen(Color.Red)
Dim point1 As New Point(Val(ax(i)) + 100, 100 - Val(az(i)))
Dim point2 As New Point(Val(ax(i + 1)) + 100, 100 - Val(az(i + 1)))

objGraphics.DrawLine(pen, point1, point2)
Next

'将objGraphics对象以指定的图形格式(这里是Gif)保存到指定的Stream对象,并输出到客户端。
objBitMap.Save(Response.OutputStream, ImageFormat.Gif)

End Sub
我想把表示横坐标的时间段均分成五份,并在图中把对应的时间表注出来,可我不会写,请帮忙,谢谢
...全文
222 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复

4,818

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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