Web Chartshtm

<Title>Web Chart Component with Multiple Charts</Title> <body>

<object classid="clsid:0002E500-0000-0000-C000-000000000046" id="chrtSpace"

width=600 height=600></Object

<H4>Data Source: Northwind Database </H4>

<SCRIPT LANGUAGE="VBScript">

Sub Window_OnLoad()

' Declare variables

Dim strConnection, rst, strSQL

Dim i, myData, cons

Dim categ(10)

Dim values1(10)

Dim values2(lo)

' specify the connection string strConnection="Provider=Microsoft.Jet.0leDB.4.0; data source=" & "C:\Program Files\Microsoft 0ffice\0ffice\Samples\Northwind.mdb"

' Create a Recordset

Set rst = Create0bject("AD0DB.Recordset")

' define the SQL query to supply the data for charting strSql = "SELECT DISTINCTR0W T0P 10 [Products].[ProductName] " _ & "AS TenMostExpensiveProducts, [Products].[UnitPrice], " _ & "Sum(CCur(([0rder Details].[UnitPrice]*[Quantity])*" _ & "(1-[Discount])/100)*100)" _

& " AS [Sales Total] FR0M Products INNER J0IN [0rder Details] " & " 0N [Products].[ProductID]=[0rder Details].[ProductID]" _ & "GR0UP BY [Products].[ProductName], [Products].[UnitPrice]" _ & "0RDER BY [Products].[UnitPrice] DESC;"

' 0pen Recordset (and execute the SQL statement above) ' use the connection string with a client-side cursor (3) ' and static dataset (3) rst.0pen strSql, strConnection, 3, 3

' get categories and values for the chart ' from the Recordset and fill the arrays rst.MoveFirst Do Until rst.E0F i = i + 1

categ(i) = rst.Fields(0) values1(i) = rst.Fields(1) values2(i) = rst.Fields(2)

rst.MoveNext Loop

'Cleanup rst.close set rst = Nothing

' Clear the chrtspace object With chrtSpace .Clear

.HasChartSpaceTitle = True

.ChartSpaceTitle.Caption = "Ten Most Expensive Products" End With

' Get constants for the Chart component set cons = chrtSpace.Constants

' Add two charts to the chartspace chrtSpace.Charts.Add 0 chrtSpace.Charts.Add 1

' Bind the charts to arrays With chrtSpace.Charts(O) .SeriesCollection.Add .SeriesCollection(0).SetData _

cons.chDimSeriesNames, cons.chDataLiteral, "Unit Price" .SeriesCollection(0).SetData _

cons.chDimCategories, cons.chDataLiteral, categ .SeriesCollection(0).SetData _

cons.chDimValues, cons.chDataLiteral, valuesl .HasLegend = True

.Type = cons.chChartTypeBarClustered

.Axes(cons.chAxisPositionBottom).NumberFormat = "$##"

End With

With chrtSpace.Charts(1) .SeriesCollection.Add .SeriesCollection(0).SetData _

cons.chDimSeriesNames, cons.chDataLiteral, "Sales" .SeriesCollection(0).SetData _

cons.chDimCategories, cons.chDataLiteral, categ .SeriesCollection(0).SetData _

cons.chDimValues, cons.chDataLiteral, values2 .HasLegend = True .HasTitle = True

.Type = cons.chChartTypeDoughnutExploded .holeSize = 20

.SeriesCollection(0).Explosion = 15 'Include data labels on the slices as percentages With .SeriesCollection(0).DataLabelsCollection.Add .HasValue = False .HasPercentage = True .Font.Size = 8

.Font.Color = RGB(255, 255, 255) ' white .Interior.Color = RGb(o, 0, 0) ' black End With

End With End Sub

You can make very complex charts with custom layout and drawings, as well as apply special formatting to different sections of your chart by using numerous properties, methods, and events organized neatly for easy lookup in the OWCDCH10.CHM help file located in the folder C:\Program Files\Common Files\Microsoft Shared\Web Components\10\1033.

0 0

Post a comment