Controls | chart | Chart control a while ago to make a chart, see all the articles in the forum, but mostly with aspchart,shortgraph components, these components are mostly foreign development to money. If you use Office Ms Chart, the results are often unsatisfactory. If you've ever used an Excel chart in Office2000, you should be impressed by the first class effect. Want to move him to your website? No problem, now you can also use ASP and VBScript to achieve the powerful features and wonderful results of Microsoft Office Chart 9.0.
example, use the data in the ADO recordset to create a chart. You first create a tab-delimited string based on the returned recordset data, and then set the chart data by SetData the method and using this string.
Source file chart.asp:
(Refer to Microsoft Help example, add some of my own changes ...)
<HTML>
<HEAD>
<meta name= "generator" content= "Microsoft FrontPage 4.0" >
</HEAD>
<BODY>
<object Id=chartspace1 classid=clsid:0002e500-0000-0000-c000-000000000046 style= "width:80%;height:350" >< /object>
<object Id=adoconnection1 classid=clsid:00000514-0000-0010-8000-00aa006d2ea4></object>
<script language=vbscript>
Sub Window_onload ()
Dim RS, categories, values
Categories = ""
Values = ""
' Open the connection to execute the SQL query (establish the "Nwind.mdb" library and create a table named "Category Sales for 1995")
Adoconnection1.open "Driver={microsoft Access DRIVER (*.mdb)};D Bq=c:\nwind.mdb"
Set rs = Adoconnection1.execute ("select * FROM [Category Sales to 1995]")
' produces a tab-delimited string for each field record
Rs. MoveFirst
Do but not Rs. Eof
Categories = Categories & Rs. Fields (0). Value & Chr (9)
Values = values & Rs. Fields (1). Value & Chr (9)
Rs. MoveNext
Loop
Rs. Close
Adoconnection1.close
' Delete the delimiter at the end of the string
Categories = Left (categories, Len (categories)-1)
Values = Left (values, Len (values)-1)
' Create a series
ChartSpace1.Clear
ChartSpace1.Charts.Add
Chartspace1.charts (0). SeriesCollection.Add
Chartspace1.charts (0). SeriesCollection (0). Caption = "Sales"
' Set the type and value of the series using the string generated by the recordset
Set C = chartspace1.constants
Chartspace1.charts (0). SeriesCollection (0). SetData c.chdimcategories, C.chdataliteral, categories
Chartspace1.charts (0). SeriesCollection (0). SetData c.chDimValues, C.chdataliteral, values
' Sets the title of the chart workspace and places a legend for the chart workspace to the right of the work area.
Chartspace1.haschartspacetitle = True
With Chartspace1.chartspacetitle
. Caption = "Monthly Sales Data"
. Font.Size = 12
. Font.Color = "#FF0000"
. Font.Bold = True
End With
ChartSpace1.HasChartSpaceLegend = True
With Chartspace1.chartspacelegend
. Position = C.chlegendpositionright
. Font.Color = "#009999"
. Font.Size = 9
End With
' Set chart type (see appendix for specific styles)
Chartspace1.charts (0). Type = c.chcharttypebarclustered
' axis ' coordinate format, style (set only when axes are available)
With Chartspace1.charts (0). Axes (C.chaxispositionbottom)
. NumberFormat = "#,# #0"
. Font.Size = 9
End With
With Chartspace1.charts (0). Axes (C.chaxispositionleft)
. Font.Color = "#0000ff"
. Fo