Microsoft KB Archive/286323

= PRB: Data Bound Office XP Chart Prints Incorrectly From Internet Explorer 5.0 =

Article ID: 286323

Article Last Modified on 8/23/2005

-

APPLIES TO


 * Microsoft Office Web Components
 * Microsoft Internet Explorer 4.0 128-Bit Edition
 * Microsoft Internet Explorer 4.01 Service Pack 2
 * Microsoft Internet Explorer 4.01 Service Pack 1
 * Microsoft Internet Explorer 4.01 Service Pack 2
 * Microsoft Internet Explorer 5.0
 * Microsoft Internet Explorer 5.01
 * Microsoft Internet Explorer (Programming) 5.01 SP1

-



This article was previously published under Q286323



SYMPTOMS
When you print a Web page containing an Office Chart component from Internet Explorer, the chart that results in the printed output does not contain the series data.



CAUSE
This problem occurs 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, the page is persisted to the Temp directory. Internet Explorer then creates a new process which 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 will not be bound and may not appear correctly in the printed output.

Internet Explorer expects 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.



RESOLUTION
To correct this problem, do either of the following things:  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 setting the DataSource property for the ChartSpace object to a DSC, add a new ElementExtension 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 &quot;More Information&quot; section below. 



Steps to Reproduce Behavior
  Use a text editor to create a .htm file that contains the following code:  

</OBJECT> <OBJECT CLASSID=&quot;clsid:0002E556-0000-0000-C000-000000000046&quot; id=ChartSpace1 style=&quot;HEIGHT:100%; WIDTH:100%&quot;></OBJECT> <SCRIPT Language=vbscript>

Sub Window_onLoad

Dim c  'For the OWC constants Set c = ChartSpace1.Constants

'Set up the connection for the Datasource control. sDBPath = &quot;C:\Program Files\Microsoft Office\Office10\Samples\Northwind.mdb&quot; DSC.ConnectionString = &quot;provider=microsoft.jet.oledb.4.0;data source=&quot; & _ sDBPath

'Add a new RecordsetDef to the Datasource control. DSC.RecordsetDefs.AddNew &quot;Select ProductName, UnitsInStock&quot; & _ &quot; from Products where Discontinued=0&quot; & _ &quot; and CategoryID=1&quot;, _ DSC.Constants.dscCommandText, &quot;ChartData&quot;

'Bind the chart to the &quot;ChartData&quot; RecordsetDef in the DSC. ChartSpace1.Clear Set ChartSpace1.DataSource = DSC ChartSpace1.DataMember = &quot;ChartData&quot;

'Create a new chart using ProductName field for Categories and the 'UnitsInStock field for Values. Dim oChart Set oChart = ChartSpace1 oChart.SetData c.chDimValues, 0, &quot;UnitsInStock&quot; oChart.SetData c.chDimCategories, 0,&quot;ProductName&quot; End Sub </SCRIPT> </BODY> NOTE: The connection string in the script uses the default path to the sample database Northwind.mdb. You may need to modify the path to Northwind.mdb in the script to a path that is appropriate for your installation of Microsoft Office XP. </li> Start Internet Explorer and browse to the .htm file you created in the previous step.</li>  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 &quot;ChartData&quot; RecordsetDef in the DSC. ChartSpace1.Clear Set ChartSpace1.DataSource = DSC Dim oElemExt                                            ' new Set oElemExt = DSC.ElementExtensions.Add(ChartSpace1.id) ' new oElemExt.ConsumesRecordset = True                       ' new ChartSpace1.DataMember = &quot;ChartData&quot; After making this modification to the script, if you refresh the page in Internet Explorer and print it again, the printed chart that results will contain the series as expected. </li></ol>

Additional Notes
File-based database systems, like Microsoft Access databases, require a file name and a path in the connection string. You can use a path that is relative to the location of your Web page. When Internet Explorer loads the persisted page in the Temp directory for printing, it binds the chart to the DSC using the connection string you supplied. If you use a relative path for a database in the connection string, the connection may fail because the current directory is the Temp directory and not the directory containing your original Web page. In this situation, you may receive the following errors when you attempt to print the Web page:

Could not find file <Database Filename>

- and -

Data provider could not be initialized.

To avoid this problem, use an absolute path, or a universal naming convention (UNC) path for a file share, in your connection string.

<div class="references_section">