Set LinearAxis, and formats the values to include a dollar sign and a thousands separator.
<!--
Code from Flex 4 Documentation "Using Adobe Flex 4".
This user guide is licensed for use under the terms of the Creative Commons Attribution
Non-Commercial 3.0 License.
This License allows users to copy, distribute, and transmit the user guide for noncommercial
purposes only so long as
(1) proper attribution to Adobe is given as the owner of the user guide; and
(2) any reuse or distribution of the user guide contains a notice that use of the user guide is governed by these terms.
The best way to provide notice is to include the following link.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
-->
<!-- charts/CustomLabelFunction.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import mx.charts.*;
import mx.collections.ArrayCollection;
[Bindable]
public var expenses:ArrayCollection = new ArrayCollection([
{Month: "Jan", Income: 2000, Expenses: 1500},
{Month: "Feb", Income: 1000, Expenses: 200},
{Month: "Mar", Income: 1500, Expenses: 500}
]);
// This method customizes the values of the axis labels.
// This signature (with 4 arguments) is for a CategoryAxis.
public function defineLabel(cat:Object,pcat:Object,ax:CategoryAxis,labelItem:Object):String{
// Show contents of the labelItem:
for (var s:String in labelItem) {
trace(s + ":" + labelItem[s]);
}
// Return the customized categoryField value:
return cat + " '07";
// Note that if you did not specify a categoryField,
// cat would refer to the entire object and not the
// value of a single field. You could then access
// fields by using cat.field_name.
}
// For a NumericAxis, you do not use the labelItem argument.
// This example uses a NumberFormatter to add a thousands
// separator.
public function defineVerticalLabel(cat:Object,pcat:Object,ax:LinearAxis):String{
return "$" + numForm.format(cat);
}
</mx:Script>
<mx:NumberFormatter id="numForm" useThousandsSeparator="true" />
<mx:Panel>
<mx:ColumnChart id="column" dataProvider="{expenses}">
<mx:horizontalAxis>
<mx:CategoryAxis categoryField="Month" title="Expenses"
labelFunction="defineLabel" />
</mx:horizontalAxis>
<mx:verticalAxis>
<mx:LinearAxis title="Income" minimum="0" maximum="2500"
labelFunction="defineVerticalLabel" />
</mx:verticalAxis>
<mx:series>
<mx:ColumnSeries xField="Month" yField="Income"
displayName="Income" />
<mx:ColumnSeries xField="Month" yField="Expenses"
displayName="Expenses" />
</mx:series>
</mx:ColumnChart>
</mx:Panel>
</mx:Application>
Related examples in the same category