Set CSpace.DataSource = oRs 'Where oRs is an ADODB.Recordset object.
CSpace.HasMultipleCharts = True
CSpace.PlotAllAggregates = c.chPlotAggregatesCharts
CSpace.SetData c.chDimCategories, c.chDataBound, "CategoryName"
CSpace.SetData c.chDimValues, c.chDataBound, Array("Qtr 1", "Qtr 2")
'Add an additional series based on literal data to each of the charts
'in the ChartSpace.
Dim oChart, oSeries
For Each oChart in CSpace.Charts
Set oSeries = oChart.SeriesCollection.Add
oSeries.SetData c.chDimSeriesNames, c.chDataLiteral, "Goal"
oSeries.SetData c.chDimValues, c.chDataLiteral, Array(30000, 20000, 25000)
Next
<html>
<head>
<style>
td {font-size:'x-small';font-family:'Sans-Serif'}
select {font-size:'x-small';font-family:'Sans-Serif'}
button {font-size:'x-small';font-family:'Sans-Serif'}
</style>
<object classid="clsid:0002E553-0000-0000-C000-000000000046" id="DSC"></object>
</head>
<body>
<table align="Center" cellspacing="5">
<tr>
<td>One Chart with a Series for Each Quarter</td>
<td><button id="btnSeriesOnOneChart" style = "width:100">Go!</button> </td>
</tr>
<tr>
<td>One Chart with One Series and Quarters As a Subordinate Category Level</td>
<td><button id="btnCategoriesOnOneChart" style="width:100">Go!</button></td>
</tr>
<tr>
<td>Multiple Charts with One Chart Per Quarter</td>
<td><button id="btnMultiChart" style="width:100">Go!</button></td>
</tr>
<tr>
<td>Multiple Charts with Plots Divided By Qtr4 Increase/Decrease</td>
<td><button id="btnDivideSeries" style="width:100">Go!</button></td>
</tr>
<tr>
<td>Series Loaded from Literal Data on Bound Chart</td>
<td><button id="btnCustom" style="width:100">Go!</button></td>
</tr>
<tr>
<td ColSpan="2">
Select a DataSource:   
<select id=DataSourceType size=1>
<option selected value=0>Bind to an ADO Recordset</option>
<option value=1>Use ChartSpace ConnectionString/CommandText Properties</option>
<option value=2>Bind to a DataSourceControl</option>
</select>
</td>
</tr>
</table>
<p align="Center">
<object classid="clsid:0002E556-0000-0000-C000-000000000046" id="CSpace" width="85%" height="50%">
</object>
</p>
</body>
<script language="VBScript">
Dim c
Set c = CSpace.Constants
Dim oRS
Function Connect()
sSQL = "SELECT [Product Sales for 1997].CategoryName, " & _
"Sum(IIf([ShippedQuarter]='Qtr 1',[ProductSales],0)) AS [Qtr 1], " & _
"Sum(IIf([ShippedQuarter]='Qtr 2',[ProductSales],0)) AS [Qtr 2], " & _
"Sum(IIf([ShippedQuarter]='Qtr 3',[ProductSales],0)) AS [Qtr 3], " & _
"Sum(IIf([ShippedQuarter] = 'Qtr 4', [ProductSales], 0)) As [Qtr 4], " & _
"IIf([Qtr 4]>[Qtr 3],'Increase in Qtr4','Decrease in Qtr4') AS Qtr4Increase " & _
"From [Product Sales for 1997] GROUP BY [Product Sales for 1997].CategoryName " & _
"HAVING (CategoryName='Confections' Or CategoryName='Meat/Poultry' Or CategoryName='Beverages')"
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\program files\microsoft office\office10\samples\northwind.mdb"
CSpace.Clear
Select Case CLng(DataSourceType.value)
Case 0: 'Bind to an ADO Recordset that is built at runtime.
Set oRS = CreateObject("ADODB.Recordset")
oRS.Open sSQL, sConn, 3, 3
Set CSpace.DataSource = oRS
Case 1: 'Bind to a Recordset by using the CommandText/ConnectionString properties.
CSpace.ConnectionString = sConn
CSpace.CommandText = sSQL
Case 2: 'Bind to a DataSourceControl (DSC).
DSC.ConnectionString = sConn
If DSC.RecordsetDefs.Count < 1 Then
DSC.RecordsetDefs.AddNew sSQL, DSC.constants.dscCommandText, "QuarterlySales"
End If
Set CSpace.DataSource = DSC
CSpace.DataMember = "QuarterlySales"
End Select
End Function
Function FormatChart(CSpaceTitle, bShowLegend)
'Hide field buttons.
CSpace.DisplayFieldButtons = False
'Add the ChartSpace Title.
CSpace.HasChartSpaceTitle = True
CSpace.ChartSpaceTitle.Caption = CSpaceTitle
CSpace.ChartSpaceTitle.Font.Size = 9
CSpace.ChartSpaceTitle.Font.Bold = True
If bShowLegend Then
For Each oChart in CSpace.Charts
oChart.HasLegend = True
oChart.Legend.Position = c.chLegendPositionBottom
Next
End If
End Function
Function btnSeriesOnOneChart_OnClick()
Connect
'One Chart with four series (one series per Quarter)
CSpace.HasMultipleCharts = False
CSpace.PlotAllAggregates = c.chPlotAggregatesSeries
CSpace.SetData c.chDimCategories, c.chDataBound, "CategoryName"
CSpace.SetData c.chDimValues, c.chDataBound, Array("Qtr 1", "Qtr 2", "Qtr 3", "Qtr 4")
CSpace.Charts(0).Type = c.chChartTypeBarClustered
sTitle = "PlotAllAggregates = chPlotAggregatesSeries"
FormatChart sTitle, True
End Function
Function btnCategoriesOnOneChart_OnClick()
Connect
'One Chart with One Series and Quarters As a Subordinate Category Level
CSpace.HasMultipleCharts = False
CSpace.PlotAllAggregates = c.chPlotAggregatesCategories
CSpace.SetData c.chDimCategories, c.chDataBound, "CategoryName"
CSpace.SetData c.chDimValues, c.chDataBound, Array("Qtr 1", "Qtr 2", "Qtr 3", "Qtr 4")
CSpace.Charts(0).Type = c.chChartTypeBarClustered
CSpace.Charts(0).SeriesCollection(0).Caption = "Sales"
sTitle = "PlotAllAggregates = chPlotAggregatesCategories"
FormatChart sTitle, True
End Function
Function btnMultiChart_OnClick()
Connect
'Four Charts with One Chart Per Quarter
CSpace.HasMultipleCharts = True
CSpace.PlotAllAggregates = c.chPlotAggregatesCharts
CSpace.SetData c.chDimCategories, c.chDataBound, "CategoryName"
CSpace.SetData c.chDimValues, c.chDataBound, Array("Qtr 1", "Qtr 2", "Qtr 3", "Qtr 4")
CSpace.ChartWrapCount = 4
sTitle = "PlotAllAggregates = chPlotAggregatesCharts"
FormatChart sTitle, False
End Function
Function btnDivideSeries_OnClick()
Connect
'Build two charts (one for Qtr3 and one for Qtr4) and then divide
'the plots based on Qtr4 increase/decrease. The result is
'four charts.
CSpace.HasMultipleCharts = True
CSpace.PlotAllAggregates = c.chPlotAggregatesSeries
CSpace.SetData c.chDimCategories, c.chDataBound, "CategoryName"
CSpace.SetData c.chDimValues, c.chDataBound, Array("Qtr 3", "Qtr 4")
CSpace.SetData c.chDimCharts, c.chDataBound, "Qtr4Increase"
CSpace.ChartWrapCount = 4
sTitle = "PlotAllAggregates = chPlotAggregatesSeries" & vbCrLF & _
"chDimCharts Dimension for Increase/Decrease in Fourth Quarter"
FormatChart sTitle, True
End Function
Function btnCustom_OnClick()
Connect
'Build two charts (one chart each for Qtr1 and Qtr2 sales).
CSpace.HasMultipleCharts = True
CSpace.PlotAllAggregates = c.chPlotAggregatesCharts
CSpace.SetData c.chDimCategories, 0, "CategoryName"
CSpace.SetData c.chDimValues, 0, Array("Qtr 1", "Qtr 2")
CSpace.Charts(0).SeriesCollection(0).Caption = "Qtr 1"
CSpace.Charts(1).SeriesCollection(0).Caption = "Qtr 2"
'Add an additional series that is based on literal data to each of the charts
'in the ChartSpace.
Dim oChart, oSeries
For Each oChart in CSpace.Charts
Set oSeries = oChart.SeriesCollection.Add
oSeries.SetData c.chDimSeriesNames, c.chDataLiteral, "Goal"
oSeries.SetData c.chDimValues, c.chDataLiteral, Array(30000, 20000, 25000)
Next
sTitle = "Bound ChartSpace With An Added Series For Literal Data"
FormatChart sTitle, True
End Function
</script>
</html>