可以直接画图,我给你vb.net的程序好了 Imports System.Drawing Imports System.Drawing.ImagingPublic Class Charts Inherits System.Web.UI.Page#Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Declare your object variables Dim i As Integer 'Build a BitMap that will act as the pallet and container for the bar graph. Here 600 is 'the width and 300 is the height. These values could also be passed as parameters. Dim objBitMap As New Bitmap(400, 200) 'Declare your Graphics objects for painting graphics on you newly created bitmap. Dim objGraphics As Graphics objGraphics = Graphics.FromImage(objBitMap) 'Set the background color to silver objGraphics.Clear(Color.Silver) 'Build an array of values for the bar and pie chart. These values could also be pulled from a database. Dim arrValues(4) As Integer arrValues(0) = 100 arrValues(1) = 135 arrValues(2) = 115 arrValues(3) = 125 arrValues(4) = 75 Dim arrValueNames(4) As String arrValueNames(0) = "Jan" arrValueNames(1) = "Feb" arrValueNames(2) = "Mar" arrValueNames(3) = "Apr" arrValueNames(4) = "May" 'Write out a title for your bar and pie chart. objGraphics.DrawString("5 Month Projection Report", New Font("Tahoma", 16), Brushes.Black, New PointF(5, 5)) 'Create a legend to describe your bar and chart. Dim symbolLeg As PointF = New PointF(335, 20) Dim descLeg As PointF = New PointF(360, 16) For i = 0 To arrValueNames.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(arrValueNames(i).ToString, New Font("Tahoma", 10), Brushes.Black, descLeg) symbolLeg.Y += 15 descLeg.Y += 15 Next i 'Loop through the values to create the Bar Chart. For i = 0 To arrValues.Length - 1 objGraphics.FillRectangle(New SolidBrush(GetColor(i)), (i * 35) + 15, 200 - arrValues(i), 20, arrValues(i) + 5) objGraphics.DrawRectangle(Pens.Black, (i * 35) + 15, 200 - arrValues(i), 20, arrValues(i) + 5) Next 'Loop through the values to create the Pie Chart. Dim sglCurrentAngle As Single = 0 Dim sglTotalAngle As Single = 0 i = 0 For i = 0 To arrValues.Length - 1 'Current Value / (sum of all the Values) * 360 degree angle sglCurrentAngle = arrValues(i) / 550 * 360 objGraphics.FillPie(New SolidBrush(GetColor(i)), 220, 95, 100, 100, sglTotalAngle, sglCurrentAngle) objGraphics.DrawPie(Pens.Black, 220, 95, 100, 100, sglTotalAngle, sglCurrentAngle) sglTotalAngle += sglCurrentAngle Next i objBitMap.Save(Response.OutputStream, ImageFormat.Gif) End Sub 'This function returns a color for the bar and pie charts. Private Function GetColor(ByVal itemIndex As Integer) As Color Dim objColor As Color Select Case itemIndex Case 0 objColor = Color.Blue Case 1 objColor = Color.Red Case 2 objColor = Color.Yellow Case 3 objColor = Color.Purple Case 4 objColor = Color.Orange Case 5 objColor = Color.Brown Case 6 objColor = Color.Gray Case 7 objColor = Color.Maroon Case Else objColor = Color.Green End Select Return objColor End FunctionEnd Class 注意,这样生成的charts.aspx直接就是张图片,如果想使用的话,直接显示或者另外做一个网页文件,插入图片让<IMG Src="Charts.aspx">就可以了
Office Web Component
http://www.csdn.net/Develop/Read_Article.asp?Id=12293
你照着做一遍,就知道怎么做图表显示了。你可以在设计面板上插入图表
比如直方图,你可以指定横轴纵轴的字段,还有分组什么的。做其它的饼图,折线图,散点图都很方便
MSCHART,怎么使用呢?
此外,我看见有的网页上简单地将不同宽度的方形图片放在好像datagrid里作为一列,这是怎么做到的?
我是初学者,问题也许太愚蠢,请回答时稍微详细点吧?谢谢,谢谢了!
感谢senoyau提供的资料,我会去学习的,但似乎有许多不会的地方,能和你单独联系向你请教吗?
直接画,很方便!
Imports System.Drawing
Imports System.Drawing.ImagingPublic Class Charts
Inherits System.Web.UI.Page#Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Declare your object variables
Dim i As Integer 'Build a BitMap that will act as the pallet and container for the bar graph. Here 600 is
'the width and 300 is the height. These values could also be passed as parameters. Dim objBitMap As New Bitmap(400, 200) 'Declare your Graphics objects for painting graphics on you newly created bitmap.
Dim objGraphics As Graphics
objGraphics = Graphics.FromImage(objBitMap)
'Set the background color to silver
objGraphics.Clear(Color.Silver) 'Build an array of values for the bar and pie chart. These values could also be pulled from a database.
Dim arrValues(4) As Integer
arrValues(0) = 100
arrValues(1) = 135
arrValues(2) = 115
arrValues(3) = 125
arrValues(4) = 75 Dim arrValueNames(4) As String
arrValueNames(0) = "Jan"
arrValueNames(1) = "Feb"
arrValueNames(2) = "Mar"
arrValueNames(3) = "Apr"
arrValueNames(4) = "May" 'Write out a title for your bar and pie chart.
objGraphics.DrawString("5 Month Projection Report", New Font("Tahoma", 16), Brushes.Black, New PointF(5, 5)) 'Create a legend to describe your bar and chart.
Dim symbolLeg As PointF = New PointF(335, 20)
Dim descLeg As PointF = New PointF(360, 16) For i = 0 To arrValueNames.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(arrValueNames(i).ToString, New Font("Tahoma", 10), Brushes.Black, descLeg)
symbolLeg.Y += 15
descLeg.Y += 15
Next i 'Loop through the values to create the Bar Chart.
For i = 0 To arrValues.Length - 1
objGraphics.FillRectangle(New SolidBrush(GetColor(i)), (i * 35) + 15, 200 - arrValues(i), 20, arrValues(i) + 5)
objGraphics.DrawRectangle(Pens.Black, (i * 35) + 15, 200 - arrValues(i), 20, arrValues(i) + 5)
Next
'Loop through the values to create the Pie Chart.
Dim sglCurrentAngle As Single = 0
Dim sglTotalAngle As Single = 0
i = 0 For i = 0 To arrValues.Length - 1
'Current Value / (sum of all the Values) * 360 degree angle
sglCurrentAngle = arrValues(i) / 550 * 360 objGraphics.FillPie(New SolidBrush(GetColor(i)), 220, 95, 100, 100, sglTotalAngle, sglCurrentAngle)
objGraphics.DrawPie(Pens.Black, 220, 95, 100, 100, sglTotalAngle, sglCurrentAngle) sglTotalAngle += sglCurrentAngle
Next i
objBitMap.Save(Response.OutputStream, ImageFormat.Gif) End Sub 'This function returns a color for the bar and pie charts.
Private Function GetColor(ByVal itemIndex As Integer) As Color
Dim objColor As Color Select Case itemIndex
Case 0
objColor = Color.Blue
Case 1
objColor = Color.Red
Case 2
objColor = Color.Yellow
Case 3
objColor = Color.Purple
Case 4
objColor = Color.Orange
Case 5
objColor = Color.Brown
Case 6
objColor = Color.Gray
Case 7
objColor = Color.Maroon
Case Else
objColor = Color.Green
End Select Return objColor
End FunctionEnd Class
注意,这样生成的charts.aspx直接就是张图片,如果想使用的话,直接显示或者另外做一个网页文件,插入图片让<IMG Src="Charts.aspx">就可以了