Microsoft KB Archive/286317

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

Article ID: 286317

Article Last Modified on 2/21/2007

-

APPLIES TO


 * Microsoft Office Web Components
 * Microsoft Office 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 &quot;c&quot; 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
  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 &quot;clsid:0002E556-0000-0000-C000-000000000046&quot;. To use the Office 2003 Chart component, change the CLASSID attribute to &quot;clsid:0002E55D-0000-0000-C000-000000000046&quot;. 



 

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 &quot;placeholder&quot; series that contains the full set of possible categories. oSer1.SetData c.chDimCategories, c.chDataLiteral, Array(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;) Set oSer2 = oChart.SeriesCollection.Add '&quot;d&quot; is omitted for this series. oSer2.SetData c.chDimSeriesNames, c.chDataLiteral, &quot;Series #1&quot; oSer2.SetData c.chDimCategories, c.chDataLiteral, Array(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;e&quot;) oSer2.SetData c.chDimValues, c.chDataLiteral, Array(10, 20, 15, 25) Set oSer3 = oChart.SeriesCollection.Add '&quot;b&quot; is omitted for this series. oSer3.SetData c.chDimSeriesNames, c.chDataLiteral, &quot;Series #2&quot; oSer3.SetData c.chDimCategories, c.chDataLiteral, Array(&quot;a&quot;, &quot;c&quot;, &quot;d&quot;) 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 &quot;placeholder&quot; series. End Sub 'Window_onLoad

   Start Internet Explorer and browse to OmitData.htm. 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 &quot;d&quot;, and the third series has omitted data for categories &quot;b&quot; and &quot;e&quot;.</ol>

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 &quot;broken,&quot; so that null data points appear as gaps within the line.

<div class="references_section">