You can customize the text in DataTips using the 'dataTipFunction' callback function. When you specify a 'dataTipFunction' callback function, you can access the data of the DataTip before Flex renders it and customizes the text.

The argument to the callback function is the event object that contains the 'hitData' property, of type mx.charts.HitData. The 'item' property of 'hitData' contains a copy of the dataProvider object for the data point.

For example, say your chart dataProvider contains a field Amount that you want apply currency formatter, then you need define a dataTipFunction in the chart tag and then format the data in the function handler.

Sample Code:

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">
  <mx:Script>
  var expenses = [{Expense: "Taxes", Amount: 2000},
                        {Expense: "Gas", Amount: 100},
                        {Expense: "Food", Amount: 200}  ];
 
 
   function showdt(eventObject:Object)
   {
    var cf = new mx.formatters.CurrencyFormatter()
    return cf.format(eventObject.hitData.item.Amount)
   }
 
  </mx:Script>
 
 
   <mx:BarChart dataProvider="{expenses}" showDataTips="true" dataTipFunction="showdt">
      <mx:verticalAxis>
         <mx:CategoryAxis dataProvider="{expenses}" categoryField="Expense"  name="Expense"/>
      </mx:verticalAxis>
      <mx:horizontalAxis>
         <mx:LinearAxis name="Amount"/>
      </mx:horizontalAxis>
      <mx:series>
         <mx:Array>
            <mx:BarSeries xField="Amount" yField="Expense" name="MY EXPENSES" />
         </mx:Array>
      </mx:series>
   </mx:BarChart>
</mx:Application>

-Ashish

 

 

 

 

 

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Dave
Sent: Tuesday, May 03, 2005 7:22 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Formatting Fields in Datatips

I need to format data (currency, number, etc.) that shows up in the
data tips of each chart column.

Thanks,

-Dave





Yahoo! Groups Links

Reply via email to