5 Replies Latest reply on Jan 30, 2009 11:05 AM by Gregory Lafrance

    Help required

    G009 Level 1
      Hey guys

      Am trying to run the following code. It displays just panel and two axes but not chart.
      Please guys look at this code and let me know where m making mistake.

      <?xml version="1.0"?>
      <!-- charts/CreateChartInActionScript.mxml -->
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      creationComplete="create()">
      <mx:HTTPService id="data" url="test.do" showBusyCursor="true" result="xmlHandler(event)" resultFormat="e4x"/>

      <mx:Script>
      <![CDATA[
      import mx.collections.ArrayCollection;
      import mx.charts.ColumnChart;
      import mx.charts.series.ColumnSeries;
      import mx.charts.CategoryAxis;
      import mx.charts.Legend;
      import mx.rpc.events.ResultEvent;

      [Bindable]public var expenses:ArrayCollection;
      public function xmlHandler(evt:ResultEvent):void{
      //Sets testInfo's root as the student. Everything else referenced in respect to this.
      expenses = evt.result.VALUES;
      }


      public var myChart:ColumnChart;
      public var series1:ColumnSeries;
      public var series2:ColumnSeries;
      public var legend1:Legend;

      public function create():void {
      data.send();
      init();
      }


      public function init():void {

      // Create the chart object and set some
      // basic properties.
      myChart = new ColumnChart();
      myChart.showDataTips = true;
      myChart.dataProvider = expenses;

      // Define the category axis.
      var hAxis:CategoryAxis = new CategoryAxis();
      hAxis.categoryField = "c10" ;
      hAxis.dataProvider = expenses;
      myChart.horizontalAxis = hAxis;

      // Add the series.
      var mySeries:Array=new Array();
      series1 = new ColumnSeries();
      series1.xField="c10";
      series1.yField="c11";
      series1.displayName = "Merchant Amount Average";
      mySeries.push(series1);

      series2 = new ColumnSeries();
      series2.xField="c10";
      series2.yField="c12";
      series2.displayName = "Account Count";
      mySeries.push(series2);

      myChart.series = mySeries;

      // Create a legend.
      legend1 = new Legend();
      legend1.dataProvider = myChart;

      // Attach chart and legend to the display list.
      p1.addChild(myChart);
      p1.addChild(legend1);
      }
      ]]></mx:Script>
      <mx:Panel id="p1" title="Column Chart Created in ActionScript"/>
      </mx:Application>
        • 1. Re: Help required
          matthew horn Level 3
          Maybe you should include the call to init() in the xmlHandler()?

          matt horn
          flex docs
          • 2. Re: Help required
            G009 Level 1
            still it doesn't work....any other suggestions.....plz guys help me with this....i have no idea why it is not working...
            • 3. Re: Help required
              Gregory Lafrance Level 6
              Sample data please... :-)
              • 4. Re: Help required
                G009 Level 1
                This is My test.xml
                <XMLDocument>

                <VALUES><c10>Nov 2005</c10><c11>205.2052</c11><c12>463290.84</c12></VALUES>
                <VALUES><c10>Dec 2005</c10><c11>241.817</c11><c12>465985.98</c12></VALUES>
                <VALUES><c10>Jan 2006</c10><c11>231.0464</c11><c12>468981.96</c12></VALUES>
                <VALUES><c10>Feb 2006</c10><c11>191.6681</c11><c12>471546</c12></VALUES>
                <VALUES><c10>Mar 2006</c10><c11>176.813</c11><c12>474083.82</c12></VALUES>
                <VALUES><c10>Apr 2006</c10><c11>205.975</c11><c12>476534.7</c12></VALUES>
                <VALUES><c10>May 2006</c10><c11>204.8433</c11><c12>479181.54</c12></VALUES>
                <VALUES><c10>Jun 2006</c10><c11>221.7901</c11><c12>481662.78</c12></VALUES>
                <VALUES><c10>Jul 2006</c10><c11>212.774</c11><c12>484301.34</c12></VALUES>
                <VALUES><c10>Aug 2006</c10><c11>222.9525</c11><c12>487294.56</c12></VALUES>
                <VALUES><c10>Sep 2006</c10><c11>215.4865</c11><c12>490040.76</c12></VALUES>
                <VALUES><c10>Oct 2006</c10><c11>197.5493</c11><c12>493675.68</c12></VALUES>
                <VALUES><c10>Nov 2006</c10><c11>205.7652</c11><c12>497132.58</c12></VALUES>
                <VALUES><c10>Dec 2006</c10><c11>238.6818</c11><c12>500185.14</c12></VALUES>
                <VALUES><c10>Jan 2007</c10><c11>226.5511</c11><c12>503381.22</c12></VALUES>
                <VALUES><c10>Feb 2007</c10><c11>189.2328</c11><c12>506010.12</c12></VALUES>
                <VALUES><c10>Mar 2007</c10><c11>174.5394</c11><c12>508840.5</c12></VALUES>
                <VALUES><c10>Apr 2007</c10><c11>204.9734</c11><c12>511492.86</c12></VALUES>
                <VALUES><c10>May 2007</c10><c11>202.2595</c11><c12>513987.9</c12></VALUES>
                <VALUES><c10>Jun 2007</c10><c11>216.6255</c11><c12>516412.56</c12></VALUES>
                <VALUES><c10>Jul 2007</c10><c11>209.8722</c11><c12>519144.96</c12></VALUES>
                <VALUES><c10>Aug 2007</c10><c11>215.9785</c11><c12>522345.18</c12></VALUES>
                <VALUES><c10>Sep 2007</c10><c11>211.2231</c11><c12>524884.38</c12></VALUES>
                <VALUES><c10>Oct 2007</c10><c11>191.099</c11><c12>527545.02</c12></VALUES>
                </XMLDocument>

                And i have already posted my complete code above. If you want i'll post struts-confi.xml
                • 5. Re: Help required
                  Gregory Lafrance Level 6
                  Your call to init should be at the end of the result handler, as HTTPService is asynchronous. Also, I think you might need XMLListCollection instead of ArrayCollection. Anyway I got it to work with this code: