Flex重置图表轴最小/最大值

时间:2009-11-11 09:41:40

标签: flex actionscript-3

我正在使用Flex显示堆积条形图,我正在动态更改数据提供者的数据。

但是,y轴的最小值和最大值不会随新数据重置。因此,如果一个数据集的值为-100,000,但下一个数据集只有正值,则y轴仍然从-100,000开始。

如何强制图表重绘。我尝试了myChart.validateNow(),dataprovider.refresh()等。

    <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, 马丁

3 个答案:

答案 0 :(得分:0)

这应该可以胜任。 `

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

`

编辑:

我将代码更改为:

<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>

并且线性轴完美更新。

答案 1 :(得分:0)

使用“堆叠”设置时,这是Flex Charting中的已知错误。

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

答案 2 :(得分:0)

尝试在actionscript中动态地将图表添加到模块或应用程序中。这会将其从内存中删除并确保重置轴。