tags:

views:

1178

answers:

3

I have a question about the ColumnChart in Flex 3. a simple ColumnChart is like:

    <mx:horizontalAxis>
       <mx:CategoryAxis 
            dataProvider="{myDP}" 
            categoryField="date"
       />
    </mx:horizontalAxis>

    <mx:series>
         <mx:ColumnSeries 
                xField="date" 
                yField="Expense" 
                displayName="Expense"
           />
           <mx:ColumnSeries 
                xField="date" 
                yField="Income" 
                displayName="Income"
           />
      </mx:series>

But how to make a ColumnChart with dynamic number of columns which come from the dataprovider? Here the columns for "expense" and "income" are hardcoded. But how can we do if they come from the dataprovider, and number is not fixed, for example, yFields can be "expense 1", "expense 2", ... "Income 1", "Income 2", ...etc.

+1  A: 

You can try to add new ColumnSeries() objects something like...

var series:Series = new Series();
for(...) // execute loop as per data provider
{
  var tmp:ColumnSeries = new ColumnSeries();
  tmp.xField....
  tmp.yField...
  ...

  series.addChild(tmp);
}

i think this, or similar solution should work

Harit K
A: 

Hi, Matt, thanks for your solution.

Just a small detail that I found. without it, it can't display.

var tmp:ColumnSeries = new ColumnSeries();

//this line is very important. this.myChart.series = [tmp];

for(var i:int=0; i< lens ; i++) // execute loop as per data provider

{

tmp = new ColumnSeries();

tmp.xField....

tmp.yField...

...

this.myChart.series[i]=tmp;

}

More details

maoanz
A: 

Hi,

Just to ask if you can add a dynamic legend to this chart?

Thanks,

Bruno Pimenta