开发者

How to show only whole numbers on a Flex chart axis?

开发者 https://www.devze.com 2023-02-21 03:18 出处:网络
I\'m trying to show some data that\'s integers but the BarChart is using fractional values on the axis which makes no sense in this scenario.Is there any way to force the chart to only use integer val

I'm trying to show some data that's integers but the BarChart is using fractional values on the axis which makes no sense in this scenario. Is there any way to force the chart to only use integer values on the axis? I don't know the range so it could be anything from 1 to 10000000, so I can't just explicitly set up e开发者_如何学Cverything.


Just ran into this myself and resolved it using a custom labelFunction for the axis I needed to change.

Chart MXML:

<mx:BarChart dataProvider="{data}" width="100%" height="100%">
    <mx:series>
            <mx:BarSeries xField="x" yField="y" />
    </mx:series>
    <mx:verticalAxis>
        <mx:LinearAxis id="verticalAxis" labelFunction="verticalAxis_labelFunction" />
    </mx:verticalAxis>
</mx:BarChart>

labelFunction script:

protected function verticalAxis_labelFunction(labelValue:Object, previousValue:Object, axis:IAxis):String
{
    if (Number(labelValue) != int(labelValue))
        return "";
    else
        return String(labelValue);
}

The one disadvantage to this approach is that the ticks will still be present for the decimal values.


I found that <mx:LinearAxis interval="1"/> works. With a small range, like 0-2 it labels with 0, 1, 2 but with a larger range, like 0-16, it labels with 0, 5, 10, 15.


Set the maximumLabelPrecision to 0. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/charts/LinearAxis.html

<mx:verticalAxis>
    <mx:LinearAxis id="valueAxis" maximumLabelPrecision="0"/>
</mx:verticalAxis>


ChartName.Series(seriesName).YValueType = ChartValueType.Int32

From - (Visual Studio 2010 Chart control: Make Y Axis an Integer value, not decimal)


I think you definitely need to show us an example where this happens. When I do it (in a very simple example), I get integers on the axis even though my data is made up of Numbers:

<fx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;

        var data:ArrayCollection = new ArrayCollection([
            { x: 5.5555333343, y: 5.111 },
            { x: 7.2, y: 9.5 },
            ]);

    ]]>
</fx:Script>

<mx:BarChart dataProvider="{data}" width="100%" height="100%">
    <mx:series>
        <mx:BarSeries xField="x" yField="y" />
    </mx:series>
</mx:BarChart>

How to show only whole numbers on a Flex chart axis?

0

精彩评论

暂无评论...
验证码 换一张
取 消