views:

916

answers:

2

Hi,

I am showing a stacked bar chart with Flex, and I am dynamically changing the data of the dataprovider.

However, the minimum and maximum for the y-axis do not get reset with the new data. So if one dataset had a value of -100,000, but the next dataset has only positive values, the y-axis still starts at -100,000.

How can I force the chart to redraw. I tried myChart.validateNow(), dataprovider.refresh(), etc.

 <mx:ColumnChart id="myChart"
     dataProvider="{_arrCol_chartData}"
     columnWidthRatio="0.8"
     type="stacked"
     width="100%"
     height="100%">
  <mx:annotationElements>
   <mx:CartesianDataCanvas id="canvas"
         includeInRanges="true"/>
  </mx:annotationElements>

  <mx:horizontalAxis>
   <mx:CategoryAxis dataProvider="{_arrCol_chartData}"
        categoryField="Month"
        id="a1"/>
  </mx:horizontalAxis>
  <mx:verticalAxisRenderers>
   <mx:AxisRenderer axis="{a1}"
        tickPlacement="none"
        showLabels="false"
        showLine="false"/>
  </mx:verticalAxisRenderers>

  <mx:series>
   <mx:ColumnSeries yField="invisible"
        displayName="invisible"
        showDataEffect="slideIn"
        hideDataEffect="slideOut">
    <mx:fill>
     <!--Set alpha to 0 to hide invisible column.-->
     <mx:SolidColor color="0xFFFFFF"
           alpha="0"/>
    </mx:fill>
   </mx:ColumnSeries>
   <mx:ColumnSeries yField="freeCashflow"
        styleName="standardSeries"
        labelFunction="setCurrencyLabel">
    <mx:fill>
     <mx:SolidColor color="0xCCCCCC"
           alpha="1"/>
    </mx:fill>
   </mx:ColumnSeries>
   <mx:ColumnSeries yField="invisibleTop"
        displayName="invisible"
        showDataEffect="slideIn"
        hideDataEffect="slideOut">
    <mx:fill>
     <!--Set alpha to 0 to hide invisible column.-->
     <mx:SolidColor color="0xFFFFFF"
           alpha="0"/>
    </mx:fill>
   </mx:ColumnSeries>
   <mx:ColumnSeries yField="bottom"
        styleName="standardSeries"
        labelFunction="setCurrencyLabel">

    <mx:fill>
     <mx:SolidColor color="0x1B95D5"
           alpha="1"/>
    </mx:fill>
   </mx:ColumnSeries>
   <mx:ColumnSeries yField="top"
        id="topColumn"
        styleName="standardSeries"
        labelFunction="setCurrencyLabel">
    <mx:fill>
     <mx:SolidColor color="0x00FF00"
           alpha="1"/>
    </mx:fill>
   </mx:ColumnSeries>
  </mx:series>
 </mx:ColumnChart>

[Bindable]  
private var _arrCol_chartData : ArrayCollection = new ArrayCollection([
   { ID: FREE_CASHFLOW, Month: "Free Cashflow", freeCashflow: 0, invisible: 0, invisibleTop: 5000 },
   { ID: CAPITAL_RESERVES, Month: "Capital Reserves", bottom: 0, invisible: 0 },
   { ID: REINVESTMENT_MONEY, Month: "Reinvestment Money", bottom: 0, invisible: 0 },
   { ID: PROFIT_SHARING, Month: "Profit Sharing", bottom: 0, invisible: 0 },
   { ID: DISTRIBUTABLE, Month: "Distributable", top: 0, invisible: 0 }]);


function changeDate() : void {
  _arrCol_chartData.getItemAt( 0 ).bottom = 1000;
  _arrCol_chartData.refresh();
}

Thx, Martin

A: 

This should do the job. `

a1.maximum = NaN;
a1.minimum = NaN; // or 0 if you want it based at zero{

`

edit:

I changed the code to look like this:

<mx:horizontalAxis>
    <mx:CategoryAxis dataProvider="{_arrCol_chartData}"
        categoryField="Month"
        id="a1"/>
</mx:horizontalAxis>
<mx:horizontalAxisRenderers>
<mx:AxisRenderer axis="{a1}"
    tickPlacement="none"
    showLabels="true"
    showLine="false"/>
</mx:horizontalAxisRenderers>

and the linear axis updated perfectly.

susichan
Well, I want it always to be the minimum of all the bars visible in the chart. I know I could iterate over the dataprovider and retrieve the minValue, but is there no way to tell the Flex Chart to readjust the axis (just resetting the axis based on the new data values)?
martin
those properties do not exist on a1, any ideas?
martin
yeah, my solution is for a LinearAxis, not CategoryAxis :). I'm looking at the code but don't have an answer yet.
susichan
This code doesn't work for me at all... you're setting your verticalaxisrenderer axis to a horizontal axis?
susichan
yes, i have this from a tutorial, works fine for me. Any ideas how to replace it?
martin
also was it intentional that showLabels was false?
susichan
I tried this now, but if the vertical axis ever starts to show negative values, the y-axis for the next chart starts at this negative values, even though the lowest newest value would be at 1000.(@showLabels = false : yes)
martin
A: 

This is a known Bug in Flex Charting when using "stacked" setting.

https://bugs.adobe.com/jira/browse/FLEXDMV-1674

martin