Microsoft KB Archive/250556: Difference between revisions

From BetaArchive Wiki
m (Text replacement - ">" to ">")
m (Text replacement - """ to """)
 
(One intermediate revision by the same user not shown)
Line 70: Line 70:
       oElemExt.ConsumesRecordset = True
       oElemExt.ConsumesRecordset = True
                     </pre>
                     </pre>
<p>This solution is illustrated in the &quot;More Information&quot; section.</p></li></ul>
<p>This solution is illustrated in the "More Information" section.</p></li></ul>




Line 85: Line 85:
<BODY>
<BODY>


<OBJECT CLASSID=&quot;clsid:0002E530-0000-0000-C000-000000000046&quot; id=DSC></OBJECT>
<OBJECT CLASSID="clsid:0002E530-0000-0000-C000-000000000046" id=DSC></OBJECT>
<OBJECT classid=clsid:0002E500-0000-0000-C000-000000000046 id=ChartSpace1
<OBJECT classid=clsid:0002E500-0000-0000-C000-000000000046 id=ChartSpace1
style=&quot;HEIGHT:100%; WIDTH:100%&quot;></OBJECT>
style="HEIGHT:100%; WIDTH:100%"></OBJECT>


<SCRIPT Language=vbscript>
<SCRIPT Language=vbscript>
Line 97: Line 97:


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


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


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


     'Create a new chart with the ProductName field for Categories and the
     'Create a new chart with the ProductName field for Categories and the
Line 133: Line 133:


To correct this problem, modify the code that performs the chart binding as follows:
To correct this problem, modify the code that performs the chart binding as follows:
<pre class="codesample">    'Bind the chart to the &quot;ChartData&quot; RecordsetDef in the DSC.
<pre class="codesample">    'Bind the chart to the "ChartData" RecordsetDef in the DSC.
     ChartSpace1.Clear
     ChartSpace1.Clear
     Set ChartSpace1.DataSource = DSC
     Set ChartSpace1.DataSource = DSC
Line 139: Line 139:
     Set oElemExt = DSC.ElementExtensions.Add(ChartSpace1.id)
     Set oElemExt = DSC.ElementExtensions.Add(ChartSpace1.id)
     oElemExt.ConsumesRecordset = True
     oElemExt.ConsumesRecordset = True
     ChartSpace1.DataMember = &quot;ChartData&quot;
     ChartSpace1.DataMember = "ChartData"
                 </pre>
                 </pre>
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.<br />
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.<br />

Latest revision as of 12:51, 21 July 2020

Article ID: 250556

Article Last Modified on 8/23/2005



APPLIES TO

  • Microsoft Office Web Components



This article was previously published under Q250556

SYMPTOMS

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.

CAUSE

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.

RESOLUTION

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.


MORE INFORMATION

Steps to Reproduce Behavior

  1. 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.

  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
    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.

Additional Notes

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:

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

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