0 Replies Latest reply on Apr 14, 2010 12:54 PM by Peter Demling

    How to skip null ColumnSeries values in a clustered ColumnChart?

    Peter Demling

      (this is a simple but difficult problem; call-out to clever chart-coders):

      When displaying multiple ColumnSeries in a clustered ColumnChart (3.5 SDK), the default behavior is to allocate a blank space when one of the series has no value in the dataprovider.  Below is a simple example (slightly modified from the base example of ColumnCharts in the help docs): when it comes to "Feb", it shows the values for Profit and Expenses, but also leaves a blank space for "VaryingOccurence".  This only happens when the Chart type is clustered (the default).

      This may seem like nitpicking, but in my context I have about 12 different series, many of which do not occur for each category value - so each of my category values has a whole lot of empty space between the clustered columns.  I just want to tell the Chart, "don't allocate any space for the chartItem in the series if its null" (or even 'if it's zero' would be fine): i.e., "ColumnSeries.showNullValues=false" - but that doesn't exist.

      Overriding updateDisplayList (to draw nothing) in a custom itemRenderer for the series does not work: the chart still allocates space for the row.  I'm thinking there's got to be someplace in ColumnChart where it's allocating space for the series (referring to properties like columnWidthRatio), but I can't find where to tell it "don't bother if the chartItem is null".

      If this is impossible to achieve via subclassing the Chart or the Series, does anyone have any creative ideas to acheive the end-result? To reiterate, the goal would be to show the result of the code below, but without the empty space for the null value in Feb.




      <?xml version="1.0"?>
      <!-- charts/BasicColumn.mxml --><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
           import mx.collections.ArrayCollection;
           public var expenses:ArrayCollection = new ArrayCollection([
              {Month:"Jan", Profit:2000, VaryingOccurence:1750, Expenses:1500},
              {Month:"Feb", Profit:1000, Expenses:200},                                         //no instance of VaryingOccurence
              {Month:"Mar", Profit:1500, VaryingOccurence:750, Expenses:500}
        <mx:Panel title="Column Chart">
           <mx:ColumnChart id="myChart" dataProvider="{expenses}" showDataTips="true" type="clustered" >
                 <mx:CategoryAxis categoryField="Month" />
                 <mx:ColumnSeries yField="Profit" displayName="Profit" />
                 <mx:ColumnSeries yField="VaryingOccurence" displayName="Varying Occurence" />
                 <mx:ColumnSeries yField="Expenses" displayName="Expenses"  />
           <mx:Legend dataProvider="{myChart}"/>