Using the chart control in Office2000 in ASP

Source: Internet
Author: User

A while ago in order to make a chart, see all the articles in the forum, but mostly with aspchart,shortgraph and other 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 its first-class results. This article demonstrates how to achieve the powerful features and wonderful effects of Microsoft Office Chart 9.0 through ASP and VBScript.

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:

<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 connection Execute SQL query (set up" Nwind.mdb "library and create 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"
"Use the string generated by the recordset to set the type and value of the series
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 workspace.
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"
. Font.Size = 9
End With
End If
End Sub
</script>
</BODY>
</HTML>

The above procedure is passed under the WIN98+PWS.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.