1 Reply Latest reply on Jan 3, 2007 10:18 PM by sf_dougco

    TipFunction to show names

    sf_dougco
      I want to use the LineChart component to show a graph that has a dynamically generated number of lines. Each line will have a name, time, and value. The time is the x axis, the value is the y axis, and when the "tip" shows I want to show all three in the popup.

      So if my source is (time is milliseconds and there are 4 lines with the "name" of the number, but it could be "line1" instead of just "1" for example):

      public var tg:ArrayCollection = new ArrayCollection( [
      {time:1165158000000, 1:13.5, 2:14, 3:16, 4:15},
      {time:1165762800000, 1:14.5, 2:11, 3:13, 4:14},
      {time:1166367600000, 1:12.5, 2:13, 3:14, 4:13},
      {time:1166972400000, 1:15.5, 2:12, 3:15, 4:12}
      ]);

      and my mxml is:

      <mx:LineChart dataProvider="{tg}" showDataTips="true"
      width="100%" height="100%" dataTipFunction="formatDataTip">
      <mx:horizontalAxis>
      <mx:DateTimeAxis dataUnits="milliseconds"
      displayLocalTime="false"
      labelFunction="myDateLabel"
      />
      </mx:horizontalAxis>
      <mx:verticalAxis>
      <mx:LinearAxis baseAtZero="false"/>
      </mx:verticalAxis>
      <mx:series>
      <mx:Array>
      <mx:LineSeries yField="1" xField="time" />
      <mx:LineSeries yField="2" xField="time" />
      <mx:LineSeries yField="3" xField="time" />
      <mx:LineSeries yField="4" xField="time" />
      </mx:Array>
      </mx:series>
      <mx:backgroundElements>
      <mx:Array>
      <mx:GridLines direction="both">
      <mx:verticalStroke>
      <mx:Stroke weight="1" color="#CCCCCC"/>
      </mx:verticalStroke>
      </mx:GridLines>
      </mx:Array>
      </mx:backgroundElements>
      </mx:LineChart>


      and my AS for the tip is:

      private function formatDataTip(hitData:HitData):String
      {
      var time:Number = hitData.item.time;
      var val:String = hitData.item[1]; // I need "1" to be based on the name of the object, i.e. line1
      return "Time: "+sDate+"<br>Value: "+val;
      }


      How do I get the tipfunction to show the name and value? The "name" being a number from 1 to N (in the above case, 4) and the value being the number that is assigned to it?

      THANKS
        • 1. Re: TipFunction to show names
          sf_dougco Level 1
          OK, I figured it out, I actually changed the lineseries to be dynamically generated and then used this for the tip display:

          private function formatDataTip(hitData:HitData):String
          {
          var time:Number = hitData.item.time;
          var unit:String = hitData.element.name;
          var num:Number = parseInt(unit);
          var val:String = hitData.item
          ;
          var sDate:Date = new Date(time);
          return "Time: "+sDate+"<br>Unit: "+unit+ "<br>Value: "+val;
          }