Microsoft KB Archive/256627

= PRB: Axis Minimum and Maximum Properties Return Incorrect Values in OnLoad Event =

Article ID: 256627

Article Last Modified on 8/23/2005

-

APPLIES TO


 * Microsoft Office Web Components
 * Microsoft Office Chart Component 9.0
 * Microsoft Visual Basic, Scripting Edition 5.0

-



This article was previously published under Q256627



SYMPTOMS
When you use the Office Chart component, the Minimum and Maximum properties of a WCScaling object return incorrect values when called during the onLoad event of a Web page in Internet Explorer. These properties might return incorrect values such as zero or a number that is very small.



CAUSE
With Internet Explorer, there is no guarantee that that all controls on a Web page have an associated window until the Web page finishes loading. Therefore, the Minimum and Maximum properties for a WCScaling object may be uninitialized during the window's onLoad event and attempts to retrieve the Minimum and Maximum properties could result in inconsistent values.



RESOLUTION
To work around this problem, retrieve the Minimum or Maximum property for a WCScaling object after Internet Explorer has associated a window with the Chart component. If you want to retrieve these properties when your Web page loads, use the window's setTimeout method in the onLoad event to allow the window to finish loading. This work around is illustrated in the "More Information" section.



MORE INFORMATION
The following steps illustrate how to reproduce the behavior of the Maximum property when called from the onLoad event. The script creates three charts at run-time and then displays the value returned from the Maximum property in the title of each chart.

Steps to Reproduce Behavior
  Use a text editor, such as Notepad, and create a text file that contains the following: 

    

<SCRIPT Language=VBScript>

Dim c

Function Window_OnLoad

Set c = ChartSpace1.Constants

CreateCharts

GetMax

End Function

Sub CreateCharts

Dim i  Dim oCSpace, oChart

'Add data to each of the three chartspace objects For i=1 to 3 Set oCSpace = document.all.item("Chartspace" & i)     oCSpace.Clear Set oChart = oCSpace.Charts.Add oChart.HasTitle=True With oChart.SeriesCollection.Add .SetData c.chDimCategories, c.chDataLiteral, _ Array("A","B","C") .SetData c.chDimValues, c.chDataLiteral, _ Array(Rnd*10, Rnd*10, Rnd*10) End With

Next

End Sub Sub GetMax

Dim i  Dim oCSpace

'Display the maximum of the value axis for each chart in the chart title For i=1 to 3 Set oCSpace = document.all.item("Chartspace" & i)     oCSpace.Charts(0).Title.Caption = "Max = " & _ oCSpace.Charts(0).Axes(c.chAxisPositionLeft).Scaling.Maximum Next

End Sub

</SCRIPT>

</HTML> </li> <li>Save the text file as ChartMax.htm.</li> <li>Start Internet Explorer and browse to ChartMax.htm.

RESULTS: The maximum value that is displayed in the Charts' titles may not be correct. The titles for one or more of the charts may indicate a maximum for the value axis that is 0 or a very small number.</li></ol>

To workaround the problem in the sample code, you could call the GetMax function, by using the window's setTimeout method so that Internet Explorer can complete the loading of the window before you retrieve the Maximum property of the value axis. To use the workaround, replace this line in the Window_onLoad event:

GetMax with:

window.setTimeout "GetMax", 200, "VBScript"

NOTE: Because this is a timing related issue, you may have to adjust the timeout so that you get the right behavior.

<div class="references_section">