1 Reply Latest reply on Aug 23, 2006 1:01 AM by vusadube

    Customizing DataTips in Pie charts

    jrecords
      When I run the following sample code, provided in the help under the topic of "Customizing DataTip values (Flex 2 Developers Guide)":

      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
      <mx:Script><![CDATA[
      import mx.charts.events.ChartItemEvent;
      import mx.collections.ArrayCollection;

      [Bindable]
      public var expenses:ArrayCollection = new ArrayCollection([
      {Expense: "Taxes", Amount: 2000},
      {Expense: "Gas", Amount: 100},
      {Expense: "Food", Amount: 200}
      ]);

      public function dtFunc(e:ChartItemEvent):String {
      return e.hitData.item.Expense + ": <B>$" + e.hitData.item.Amount + "</B>";
      }
      ]]></mx:Script>
      <mx:BarChart dataProvider="{expenses}" showDataTips="true" dataTipFunction="dtFunc">
      <mx:verticalAxis>
      <mx:CategoryAxis dataProvider="{expenses}" categoryField="Expense"
      name="Expense"/>
      </mx:verticalAxis>
      <mx:horizontalAxis>
      <mx:LinearAxis name="Amount"/>
      </mx:horizontalAxis>
      <mx:series>
      <mx:BarSeries xField="Amount" yField="Expense"/>
      </mx:series>
      </mx:BarChart>
      </mx:Application>

      I'm receiving the following error when I hover my mouse over any of the area's in the chart:

      TypeError: Error #1034: Type Coercion failed: cannot convert mx.charts::HitData@31ff801 to mx.charts.events.ChartItemEvent.
      at mx.charts.chartClasses::ChartBase/::invokeDTFunction()
      at mx.charts::HitData/get displayText()
      at mx.charts.chartClasses::DataTip/set data()
      at mx.charts.chartClasses::ChartBase/::updateDataTipToMatchHitSet()
      at mx.charts.chartClasses::ChartBase/::processRollEvents()
      at mx.charts.chartClasses::ChartBase/::mouseMoveHandler()

      I know the sample code is not using a Pie chart, but I'm getting the same error when using a Pie chart as well. Anyone have any idea what is causing this?

      Thanks,
      Jim
        • 1. Re: Customizing DataTips in Pie charts
          vusadube
          Something wrong with flex docs, the dataTip function takes HitData Object as parameter and not ChartItemEvent.
          public function dtFunc(h:HitData):String {
          return h.item.Expense + ": <B>$" + h.item.Amount + "</B>";
          }

          Somehow, the code given in their examples does not run in Flex 2. I'm trying to format datatips in a bar chart with multible series but it's causing me headaches!