How To Create Null (or Omitted) Data Points with the Office Chart Component (286317)



The information in this article applies to:

  • Microsoft Office 2003 Web Components
  • Microsoft Office XP Web Components
  • Microsoft Office Chart Component 9.0

This article was previously published under Q286317

SUMMARY

This article illustrates how you can programmatically create a null (or omitted) data point for a series on a Chart component.

MORE INFORMATION

To omit a data point value in a series, you must have at least one series that contains the full set of possible categories for the chart. To illustrate, if you have a series with the full set of categories (a, b, c, d, and e), you can have another series that uses some of those categories and omits others (for example, a, b, d, and e). In this situation, the chart has a placeholder for the "c" category but does not show a value for that category in the second series. If desired, you can hide the first series by not providing any values for the series and by hiding its legend entry.

Sample

  1. Paste the following code into any text editor and save it as OmitData.htm.NOTE: The clsid provided in the code is for the Office 2000 Chart component. To use the Office 2002 Chart component, change the CLASSID attribute to "clsid:0002E556-0000-0000-C000-000000000046". To use the Office 2003 Chart component, change the CLASSID attribute to "clsid:0002E55D-0000-0000-C000-000000000046".
    <HTML>
    
    <BODY>
    
    <OBJECT CLASSID="clsid:0002E500-0000-0000-C000-000000000046" id=ChartSpace1>
    </OBJECT>
    
    <script language=vbscript>
    Option Explicit
    
    Sub Window_onLoad()
    
    
        Dim c, oChart, oSer1, oSer2, oSer3
        
        Set c = ChartSpace1.Constants
        
        Set oChart = ChartSpace1.Charts.Add
        oChart.Type = c.chChartTypeLineMarkers
        
        Set oSer1 = oChart.SeriesCollection.Add 'A "placeholder" series that contains the full set of possible categories.
        oSer1.SetData c.chDimCategories, c.chDataLiteral, Array("a", "b", "c", "d", "e")
        
        Set oSer2 = oChart.SeriesCollection.Add '"d" is omitted for this series.
        oSer2.SetData c.chDimSeriesNames, c.chDataLiteral, "Series #1"
        oSer2.SetData c.chDimCategories, c.chDataLiteral, Array("a", "b", "c", "e")
        oSer2.SetData c.chDimValues, c.chDataLiteral, Array(10, 20, 15, 25)
        
        Set oSer3 = oChart.SeriesCollection.Add '"b" is omitted for this series.
        oSer3.SetData c.chDimSeriesNames, c.chDataLiteral, "Series #2"
        oSer3.SetData c.chDimCategories, c.chDataLiteral, Array("a", "c", "d")
        oSer3.SetData c.chDimValues, c.chDataLiteral, Array(5, 4, 9)
        
        oChart.HasLegend = True
        oChart.Legend.LegendEntries(0).Visible = False 'Hide the legend entry for the "placeholder" series.
           
    End Sub 'Window_onLoad()
    
    </script>
    
    </BODY>
    </HTML>
    					
  2. Start Internet Explorer and browse to OmitData.htm.
  3. The chart that results contains three series. The first series does not appear on the plot itself and its legend entry is hidden; this first series simply acts as a placeholder for the full category set (a, b, c, d, and e). The second series on the chart has omitted data for category "d", and the third series has omitted data for categories "b" and "e".
Note that even though a series in the sample may contain null, or omitted, data points, the series line is still continuous; there is no way to change this behavior. A series line cannot be discontinuous, or "broken," so that null data points appear as gaps within the line.

REFERENCES

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

240263 How To Create a Combination Chart with the Chart Web Component

235885 How To Use the Chart Web Component with Visual Basic

For more information, see the following Microsoft Web site:

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


Modification Type:MinorLast Reviewed:8/23/2005
Keywords:kbhowto kbOfficeWebChart KB286317