Microsoft KB Archive/286323

From BetaArchive Wiki

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 "More Information" section below.


MORE INFORMATION

Steps to Reproduce Behavior

  1. Use a text editor to create a .htm file that contains the following code:

    <HTML>
       <BODY>
    
       <OBJECT CLASSID="clsid:0002E553-0000-0000-C000-000000000046"
    id=DSC></OBJECT>
       <OBJECT CLASSID="clsid:0002E556-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 = ChartSpace1.Constants
    
           'Set up the connection for the Datasource control.
           sDBPath = "C:\Program Files\Microsoft Office\Office10\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 using ProductName field for Categories and the
           'UnitsInStock field for Values.
           Dim oChart
           Set oChart = ChartSpace1
           oChart.SetData c.chDimValues, 0, "UnitsInStock"    
           oChart.SetData c.chDimCategories, 0,"ProductName"
       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.

  2. Start Internet Explorer and browse to the .htm file you created in the previous step.
  3. 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                                             ' new
           Set oElemExt = DSC.ElementExtensions.Add(ChartSpace1.id) ' new 
           oElemExt.ConsumesRecordset = True                        ' new
           ChartSpace1.DataMember = "ChartData"
                            

    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.

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.

REFERENCES

288907 INFO: Creating Bound Charts with the Office XP Chart


286320 HOWTO: Bind the Office XP Chart Component to a PivotTable


In addition, the following Microsoft Web sites provide resources for scripting and working with the Microsoft Office Web components:

Microsoft Office Web Components
http://support.microsoft.com/ofd

Microsoft Office Developer Center
http://msdn.microsoft.com/office/



(c) Microsoft Corporation 2001, All Rights Reserved. Contributions by Chris Jensen, Microsoft Corporation.



Additional query words: owc owc10 webchart ie5

Keywords: kbofficewebchart kbprb KB286323