ZedGraph图形控件来生成图片,有很多东西需要继续研究。
Imports ZedGraph
Imports System.Drawing
Public Class graph
Inherits System.Web.UI.Page
Dim ls_projid As String = ""
Protected Sub ZedGraphWeb2_RenderGraph(ByVal z As ZedGraph.Web.ZedGraphWeb, _
ByVal g As System.Drawing.Graphics, _
ByVal masterPane As ZedGraph.MasterPane) Handles ZedGraphWeb2.RenderGraph
' Get the GraphPane so we can work with it
Dim myPane As GraphPane = masterPane(0)
' Set the titles and axis labels
myPane.Title.Text = "项目进度报表"
myPane.XAxis.Title.Text = "日期"
myPane.YAxis.Title.Text = "进度"
'进度条0 - 100
myPane.YAxis.Scale.Min = 0
myPane.YAxis.Scale.Max = 100
'myPane.YAxis.Scale.MinGrace = 0.2
'myPane.YAxis.Scale.MaxGrace = 0.2
'myPane.Y2Axis.Scale.MinGrace = 0.2
'myPane.Y2Axis.Scale.MaxGrace = 0.2
' Make up some data points from the Sine function
Dim list As New PointPairList()
Dim list2 As New PointPairList()
Dim i As Integer, x As Double, y As Double, y2 As Double
Dim d As Date
'取得对应的ID号
Dim ds As DataSet
ds = Config.GetDs("select AchieveDate,TargetProgress,FactProgress from tbl_projectprogress where Id_InProject='" & ls_projid & "' order by AchieveDate")
If ds.Tables(0).Rows.Count > 0 Then
For i = 0 To ds.Tables(0).Rows.Count - 1
d = ds.Tables(0).Rows(i)("AchieveDate")
x = New XDate(d)
y = ds.Tables(0).Rows(i)("TargetProgress")
y2 = ds.Tables(0).Rows(i)("FactProgress")
list.Add(x, y)
list2.Add(x, y2)
Next i
End If
'd = "2008-3-2"
'x = New XDate(d)
'y = 10
'y2 = 5
'list.Add(x, y)
'list2.Add(x, y2)
'For i = 0 To 35
' x = New XDate(1995, i + 1, 1)
' y = Math.Sin(i * Math.PI / 15.0)
' y2 = 2 * y
' list.Add(x, y)
' list2.Add(x, y2)
'Next i
' Generate a blue curve with circle symbols, and "My Curve 2" in the legend
Dim myCurve2 As LineItem = myPane.AddCurve("目标进度", list, Color.Blue, _
SymbolType.Circle)
' Fill the area under the curve with a white-red gradient at 45 degrees
'myCurve2.Line.Fill = New Fill(Color.White, Color.Red, 45.0F)
' Make the symbols opaque by filling them with white
myCurve2.Symbol.Fill = New Fill(Color.White)
' Generate a red curve with diamond symbols, and "My Curve" in the legend
Dim myCurve As LineItem = myPane.AddCurve("实际进度", _
list2, Color.MediumVioletRed, SymbolType.Diamond)
' Fill the area under the curve with a white-green gradient
'myCurve.Line.Fill = New Fill(Color.White, Color.Green)
' Make the symbols opaque by filling them with white
myCurve.Symbol.Fill = New Fill(Color.White)
' Set the XAxis to date type
myPane.XAxis.Type = AxisType.Date
myPane.XAxis.CrossAuto = True
' Fill the axis background with a color gradient
myPane.Chart.Fill = New Fill(Color.White, Color.LightGoldenrodYellow, 45.0F)
masterPane.AxisChange(g)
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim sqlstr As String
Dim ds As DataSet
Dim i As Integer
sqlstr = "select id,itemdes from dbo.tbl_project where parentid='0' and status='1'"
ds = Config.GetDs(sqlstr)
drpProject.Items.Add("请选择")
drpProject.Items(0).Value = ""
If ds.Tables(0).Rows.Count > 0 Then
For i = 0 To ds.Tables(0).Rows.Count - 1
drpProject.Items.Add(ds.Tables(0).Rows(i)("itemdes"))
drpProject.Items(i + 1).Value = ds.Tables(0).Rows(i)("id")
Next i
End If
End If
End Sub
Protected Sub cmdShow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdShow.Click
ls_projid = drpProject.SelectedValue
End Sub
End Class