3 Replies Latest reply on Aug 11, 2009 8:55 AM by xandesign

    Urgently need help creating a line chart from an xml file using AS3

    xandesign

      Hi,

       

      I've been trying to create a line chart from an xml file using AS3 but I can't get it to display my data, I just see a blank line chart. I want my line chart to display the date attribute in the series tag as the series display name in the legend and the other tags (i.e. l100, l200, l300, etc...) to be used as the line series data (see attached screenshot).

       

      I'd really appreciate any help with this, I've included a sample of my xml file and my actionscript code below. I'm not sure if I've built my xml file properly for this type of chart, so any suggestions are welcome.

       

      Thanks in advance,

       

      Xander

       

       

      XML File

      <?xml version="1.0" encoding="UTF-8"?>
      <dataset>
          <series date="08-06-2009">
              <l100>29.00</l100>
              <l200>12.21</l200>
              <l300>7.34</l300>
          </series>
          <series date="15-06-2009">
              <l100>21.79</l100>
              <l200>8.96</l200>
              <l300>3.97</l300>
          </series>
      </dataset>

       

       

      Actionscript File

      <--- This code segment is created in the handler for the call to load the XML file and passed to the chart function below -->

      var result:XML = new XML(event.target.data);

      var seriesData:XMLList = result.elements('series') as XMLList;

      <---                                               ---->

       

      var chart:LineChart = new LineChart();

       

      chart.id = "chartquery1";
      chart.percentHeight = 80;
      chart.showDataTips = true;
      chart.dataProvider = seriesData;

       

      var axis:CategoryAxis = new CategoryAxis();
      axis.categoryField = "@name";
      chart.horizontalAxis = axis;

       

      var series:LineSeries = new LineSeries();
      series.yField = seriesData.*.text();      <-- I know this is wrong but don't know what the solution is -->
      series.displayName = seriesData.@date;   <-- I know this is wrong but don't know what the solution is -->
      seriesArray.push(series);

       

      chart.series = seriesArray;

       

      legend.direction = "horizontal";
      legend.dataProvider = chart;

        • 1. Re: Urgently need help creating a line chart from an xml file using AS3
          apmyhr

          From looking over your code real quick I think you have a couple of problems.  First of all, I would use a DateTime axis instead of a Category if your going to do a line chart based on time.

           

          Then, with your series, you would want to set,

          series.xField = "date";

          series.yField = "l100";  (or) "l200"; (or) "l300";

           

          I hope this helps

          • 2. Re: Urgently need help creating a line chart from an xml file using AS3
            xandesign Level 1

            apmyhr,

             

            The screenshot I uploaded doesn't seem to be available to view yet so I will describe what I need the line chart to look like.

             

            1. Along the x axis of the line chart I want it to display l100, l200, l300... l1000.
            2. Along the y axis I want numbers displayed to represent the values of the <l100>, <l200>, etc... tags i.e. from 0.00 to 30.00.
            3. There should be 1 line drawn for each of the dates in my xml file with the values for each date representing a point on the line chart.

             

            Using the xml file I included in the 1st post above as an example, there should be 2 lines on the chart, one for the date 08-06-2009 with 3 points, 29.00, 12.21 & 7.34 and a 2nd line for the date 15-06-2009 with the 3 points, 21.79, 8.96 & 3.97. Also, I want the legend to display the date as the key to the lines.

             

            This all has to be as dynamic as possible as the data could have any values or dates.

             

            Any help would be very much appreciated,

             

            Xander