2 Replies Latest reply on Jun 28, 2009 11:59 PM by sri harsha namala

    How to show coordinate on datatip?

    ahmadmoonsyi Level 1

      i had found this in Flex Help, but the coordinate value is shown in the textarea. how to make it appeared in the datatip? better still, can someone help to modify this so that it can be called in the chart's dataTipFunction=""?

       

       

      public function handleMouseMove(e:MouseEvent):void {
              // Use coordinates to get HitData object of
              // current data point.
              var hda:Array =
                  chart.findDataPoints(e.currentTarget.mouseX,
                  e.currentTarget.mouseY);
             
              //ta is the ID for the textarea       
              if (hda[0]) {
                 ta.text = "Found data point " +
                      hda[0].chartItem.index + " (x/y):" +
                      Math.round(hda[0].x) + "," +
                      Math.round(hda[0].y) + "\n";
                 ta.text += "Expenses:" + hda[0].item.Expenses;
              } else {
                 ta.text = "No data point found  (x/y):" +
                      Math.round(e.currentTarget.mouseX) +
                      "/" + Math.round(e.currentTarget.mouseY);
              }
           }

        • 1. Re: How to show coordinate on datatip?
          sri harsha namala Level 2

          Hi,

           

          U can use the DataTip Function available in Chart to get the CoOrdinate Position,I think this might help You

          • 2. Re: How to show coordinate on datatip?
            sri harsha namala Level 2

            Hi,

                   Use DataTipFunction which is available in Charts ,Following code might help u

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
            <mx:Script>
                <![CDATA[
                    import mx.charts.HitData;
                    import mx.collections.ArrayCollection;
                    [Bindable]
                    public var arr:ArrayCollection=new ArrayCollection();
                    private function init():void
                    {
                        for(var i:int=0;i<100;i++)
                        {
                            arr.addItem({Y:Math.random()*i})
                        }
                    }
                    private function dtf(hd:HitData):String
                    {
                        return "X->"+hd.x+" Y ->"+hd.y;
                    }
                       
                       
                ]]>
            </mx:Script>
                <mx:LineChart id="lineChart" dataProvider="{arr}" dataTipFunction="dtf" showDataTips="true">
                <mx:series>
                    <mx:LineSeries yField="Y" />
                 </mx:series>
                 </mx:LineChart>
            </mx:Application>