Microsoft KB Archive/250556
Article ID: 250556
Article Last Modified on 8/23/2005
- Microsoft Office Web Components
This article was previously published under Q250556
When you print a Web page that contains an Office 2000 Chart component from Microsoft Internet Explorer version 5.0, the chart that results in the printed output does not contain the series data.
This problem may occur when the chart is bound to a DataSource Control (DSC) or an ActiveX Data Objects (ADO) Recordset with script. When you print a Web page from Internet Explorer 5.0, the page is persisted to the Temp folder. Internet Explorer then creates a new process that loads the persisted page for printing. When the persisted page is loaded, script is not run; therefore, if you use script in the onLoad event for binding the chart, the chart is not bound and may not appear correctly in the printed output.
Internet Explorer 5.0 instructs that controls on a Web page persist their data before saving the temporary page for printing. Because the chart does persist literal data into its XMLData parameter, this problem does not occur when the chart uses literal data.
To correct this problem, do one of the following:
- Upgrade Internet Explorer to version 5.5. The printing facilities in Internet Explorer 5.5 have changed so that this problem no longer occurs. - or -
Use the DSC to manage binding to the chart. After you set the DataSource property for the ChartSpace to a DSC, add a new ElementExtension object to the DSC that is tied to the ChartSpace and then set the ConsumesRecordset property of that ElementExtension object to TRUE:
Set ChartSpace1.DataSource = DSC Set oElemExt = DSC.ElementExtensions.Add(ChartSpace.id) oElemExt.ConsumesRecordset = True
This solution is illustrated in the "More Information" section.
Steps to Reproduce Behavior
Using a text editor such as Notepad, create an .htm file that contains the following code:
<HTML> <BODY> <OBJECT CLASSID="clsid:0002E530-0000-0000-C000-000000000046" id=DSC></OBJECT> <OBJECT classid=clsid:0002E500-0000-0000-C000-000000000046 id=ChartSpace1 style="HEIGHT:100%; WIDTH:100%"></OBJECT> <SCRIPT Language=vbscript> Sub Window_onLoad() Dim c 'For the OWC constants. Set c = DSC.Constants 'Set up the connection for the DataSource Control. sDBPath = "C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb" DSC.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=" & _ sDBPath 'Add a new RecordsetDef to the DataSource Control. DSC.RecordsetDefs.AddNew "Select ProductName, UnitsInStock" & _ " from Products where Discontinued=0" & _ " and CategoryID=1", _ DSC.Constants.dscCommandText, "ChartData" 'Bind the chart to the "ChartData" RecordsetDef in the DSC. ChartSpace1.Clear Set ChartSpace1.DataSource = DSC ChartSpace1.DataMember = "ChartData" 'Create a new chart with the ProductName field for Categories and the 'UnitsInStock field for Values. Dim oChart, oSeries Set oChart = ChartSpace1.Charts.Add Set oSeries = oChart.SeriesCollection.Add oSeries.SetData c.chDimCategories, 0, 0 oSeries.SetData c.chDimValues, 0, 1 End Sub </SCRIPT> </BODY>
NOTE: The connection string in the script uses the default path to the Northwind.mdb sample database. You may need to modify the path to Northwind.mdb in the script to a path that is appropriate for your installation of Office.
- Start Internet Explorer and browse to the .htm file you created in the previous step.
- On the File menu, click Print, and then click OK.
Examine the printed output. Note that the chart's plot area, gridlines, and axes appear, but the series data is missing from the printed chart.
To correct this problem, modify the code that performs the chart binding as follows:
'Bind the chart to the "ChartData" RecordsetDef in the DSC. ChartSpace1.Clear Set ChartSpace1.DataSource = DSC Dim oElemExt Set oElemExt = DSC.ElementExtensions.Add(ChartSpace1.id) oElemExt.ConsumesRecordset = True ChartSpace1.DataMember = "ChartData"
After you make this modification to the script, refresh the page in Internet Explorer, and print the page again, the printed chart contains the series as expected.
File-based database systems, such as Microsoft Access databases, require a filename and a path in the connection string. The path that you use can be a path that is relative to the location of your Web page. When Internet Explorer loads the persisted page in the Temp folder for printing, it binds the chart to the DSC by using the connection string that you supplied. If you use a relative path for a database in the connection string, the connection may fail because the current folder is the Temp folder and not the folder that contains your original Web page. In this situation, you may receive the following errors when you attempt to print the Web page:
To avoid this problem, use an absolute path, or a universal naming convention (UNC) path for a file share, in your connection string.
Stearns, Dave. Programming Microsoft Office 2000 Web Components. Redmond, WA: Microsoft Press, 1999.
For more information about the Microsoft Office Web Components, see the following Microsoft Web site:
Using Office Web Components http://support.microsoft.com/ofd
For sample code that demonstrates solutions using the Office 2000 Web Components with VBScript and ASP, see the following article in the Microsoft Knowledge Base:
258187 OWebComp.exe Contains Scripting Samples for the Office Web Components
Additional query words: webchart owc
Keywords: kbofficewebchart kbprb KB250556