maoanz
maoanz

Reputation: 151

ColumnChart with dynamic number of columns

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.

Upvotes: 1

Views: 3318

Answers (2)

maoanz
maoanz

Reputation: 151

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

Upvotes: 1

Harit K
Harit K

Reputation: 358

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

Upvotes: 1

Related Questions