5 Replies Latest reply on Mar 10, 2011 6:12 PM by smart2008_tw

    need help with DataTipFunction

    smart2008_tw

      Dear Friend:

      how can i chage data tip data by looping through array and assign value to it and return.for example:

       

      var arry:Array=new Array();

      arry.push(....);

      arry.push(....);

       

      function myDataTipFunction(hitData:HitData):String {

       

         for(var property:Object in hitData.item){  

            hitData.item.Month=hitData.item.Month+arry[i];

          }

            retrun hitData.item.Month

      }

       

      for my code,the data remain no chage.so,how to do this? thank for helping

        • 1. Re: need help with DataTipFunction
          snkd Level 1

          instead of  doing

           

             for(var property:Object in hitData.item){ 

                hitData.item.Month=hitData.item.Month+arry[i];//sometimes value may not reflect

              }

                retrun hitData.item.Month

           

          what about returning value hitData.item.Month+arry[i];

           

                return hitData.item.Month+arry[i];

           

           

          example from http://livedocs.adobe.com/flex/3/html/help.html?content=charts_displayingdata_08.html

           

               public function myDataTipFunction(e:HitData):String {
                  var s:String;
                  s = ColumnSeries(e.element).displayName + "\n";
                  s += "Profit: $" + (e.item.Income - e.item.Expenses);
                  return s;
               }
          • 2. Re: need help with DataTipFunction
            huangxinghui

            what's your data source, can you give more codes

             

            thanks

            • 3. Re: need help with DataTipFunction
              smart2008_tw Level 1

              here is my code, but i think it is not correct

              i try to append time to month such as Jan:11:30:44,Feb:18:10:20 ...etc

              <?xml version="1.0"?>
              <!-- charts/BasicLine.mxml -->
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
                <mx:Script><![CDATA[
                   import mx.collections.ArrayCollection;
                   [Bindable]
                   public var expenses:ArrayCollection = new ArrayCollection([
                      {Month:"Jan", Profit:2000},
                      {Month:"Feb", Profit:1000},
                      {Month:"Mar", Profit:1500}
                   ]);
                 [Bindable]
                  var i:int=0;
                 [Bindable]
                   public var timeArry:ArrayCollection = new ArrayCollection([
                      {Time:"11:30:44"},
                      {Time:"18:10:20"},
                      {Time:"21:15:19"}
                   ]);
               
                 public function dtFunc(hd:HitData):String {
                      return hd.item.Month +":"+timeArry.getItemAt(i).Time
                       i=i+1;
                   }

                ]]></mx:Script>
                <mx:Panel title="Line Chart">
                   <mx:LineChart id="myChart"
                      dataProvider="{expenses}"
                      showDataTips="true"
                dataTipFunction="dtFunc"
                   >
                    
                      <mx:series>
                         <mx:LineSeries
                              yField="Profit"
                  xField="Month"
                              displayName="Profit"
                         />
                       
                      </mx:series>
                   </mx:LineChart>
                   <mx:Legend dataProvider="{myChart}"/>
                </mx:Panel>
              </mx:Application>

              • 4. Re: need help with DataTipFunction
                huangxinghui Level 1

                change code like this:

                 

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
                <mx:Script>
                <![CDATA[
                  import mx.charts.HitData;
                     import mx.collections.ArrayCollection;
                    
                     [Bindable]
                     public var expenses:ArrayCollection = new ArrayCollection([
                        {Month:"Jan", Profit:2000},
                        {Month:"Feb", Profit:1000},
                        {Month:"Mar", Profit:1500}
                     ]);
                       
                    [Bindable]
                    public var timeArry:ArrayCollection = new ArrayCollection([
                        {Time:"11:30:44"},
                        {Time:"18:10:20"},
                        {Time:"21:15:19"}
                     ]);
                 
                    public function dtFunc(hd:HitData):String {
                        return hd.item.Month +":"+timeArry.getItemAt(expenses.getItemIndex(hd.item)).Time
                     }

                  ]]></mx:Script>
                  <mx:Panel title="Line Chart">
                     <mx:LineChart id="myChart" dataProvider="{expenses}" showDataTips="true" dataTipFunction="dtFunc">
                      <mx:horizontalAxis>
                            <mx:CategoryAxis categoryField="Month"/>
                        </mx:horizontalAxis>

                        <mx:series>
                           <mx:LineSeries yField="Profit" displayName="Profit"/>
                        </mx:series>
                     </mx:LineChart>
                     <mx:Legend dataProvider="{myChart}"/>
                  </mx:Panel>

                </mx:Application>

                hope it will help for you

                • 5. Re: need help with DataTipFunction
                  smart2008_tw Level 1

                  hello huangxinghui ,it works, thank for helping. i appreciate a lot