Article ID: 286211
Article Last Modified on 2/20/2007
APPLIES TO
- Microsoft Office Web Components
- Microsoft Office Web Components
This article was previously published under Q286211
SUMMARY
This article provides sample code that illustrates how you can create a combination chart using the Microsoft Office XP Chart component or the Microsoft Office 2003 Chart component.
MORE INFORMATION
Using the Office XP Chart component or the Office 2003 Chart component, you can create a combination chart that contains a mixture of columns, lines, and areas. Both charts and series have a Type property. Setting the Type property for a chart changes the chart type for every series, whereas setting the Type property for a series changes only that series if the new series type is compatible with the rest of the chart. If the new series type is not compatible with a combination chart, all series in the chart reflect the new type.
The following sample demonstrates run-time creation of a combination chart with two series: one series has a column type and the other series has a line type. The first series has values in the range 0 to 8000, and the second series has values in the range 0.10 to 0.25. If the two series were plotted against a single value axis, the line would appear dwarfed in comparison to the column. Hence, the line series is plotted against its own value axis with scaling that is different from the axis for the column series.
Note The ability to have two value axes with separate scaling is a feature that is introduced with Office XP.
Sample Code
<html> <body> <object id=ChartSpace1 classid=CLSID:0002E556-0000-0000-C000-000000000046 style="width:100%;height:350"></object> <script language=vbscript> Sub Window_OnLoad() Dim oChart Dim oSeries1, oSeries2 Dim oAxis1, oAxis2 Dim oConst ChartSpace1.Clear Set oConst = ChartSpace1.Constants 'Create a new chart in the ChartSpace. Set oChart = ChartSpace1.Charts.Add 'Add a series of type Column. Set oSeries1 = oChart.SeriesCollection.Add oSeries1.Caption = "Sales" oSeries1.SetData oConst.chDimCategories, oConst.chDataLiteral, _ Array("A", "B", "C", "D") oSeries1.SetData oConst.chDimValues, oConst.chDataLiteral, _ Array(5000, 6025, 5575, 5900) oSeries1.Type = oConst.chChartTypeColumnClustered 'Add a second series of type Line. Set oSeries2 = oChart.SeriesCollection.Add oSeries2.Caption = "Discount" oSeries2.SetData oConst.chDimCategories, oConst.chDataLiteral, _ Array("A", "B", "C", "D") oSeries2.SetData oConst.chDimValues, oConst.chDataLiteral, _ Array(0.1, 0.2, 0.1, 0.15) oSeries2.Type = oConst.chChartTypeLine ' Change the Min/Max, Numberformat and Gridlines for the value-axis of the first series. Set oAxis1 = oChart.Axes(oConst.chAxisPositionLeft) oAxis1.Scaling.Maximum = 8000 oAxis1.Scaling.Minimum = 0 oAxis1.NumberFormat = "$0" oAxis1.HasMajorGridlines = False ' Ungroup the series so that they can have separate value-axis scaling. oSeries2.Ungroup True ' Add a new value-axis for the second series. Position the new axis on the right side 'of the chart and modify the gridlines and numberformat. Set oAxis2 = oChart.Axes.Add(oSeries2.Scalings(oConst.chDimValues)) oAxis2.Position = oConst.chAxisPositionRight oAxis2.HasMajorGridlines = False oAxis2.NumberFormat = "0%" 'Display the legend. oChart.HasLegend = True oChart.Legend.Position = oConst.chLegendPositionBottom 'Display the title for the chart. oChart.HasTitle = True oChart.Title.Caption = "Sales & Discounts" End Sub </script> </body> </html>
REFERENCES
For additional information about Office XP Chart components, visit the following Microsoft Web sites and Knowledge Base articles:
288907 INFO: Binding the Office XP Chart Component to a Data Source
286320 How To Bind the Office Chart Component to a PivotTable
289288 INFO: Using Timescale Axes with the Office Chart Component
For additional information about creating a combination chart with the Office Chart component, click the following article number to view the article in the Microsoft Knowledge Base:
240263 How To Create a Combination Chart with the Chart Web Component
(c) Microsoft Corporation 2001, All Rights Reserved. Contributions by Lori B. Turner, Microsoft Corporation.
Additional query words: webchart 10 owc owc10
Keywords: kbhowto kbofficewebchart KB286211