Reputation: 21
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 everything.
Upvotes: 2
Views: 2371
Reputation: 21
ChartName.Series(seriesName).YValueType = ChartValueType.Int32
From - (Visual Studio 2010 Chart control: Make Y Axis an Integer value, not decimal)
Upvotes: 0
Reputation: 11
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>
Upvotes: 1
Reputation: 111
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.
Upvotes: 3
Reputation: 1690
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.
Upvotes: 5
Reputation: 48127
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 Number
s:
<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>
Upvotes: -1