1 Reply Latest reply on Jun 28, 2011 5:36 AM by relaxatraja

    How to dynamically create charts

    W M Chin Level 1

      Hi everyone, I am still a Flex beginner.

       

      I have the PHP code which has the x and y values for the charts and the labels for the axis'.

       

      function getChartData() {

              $s1 = "SELECT * FROM lu_chart_view LEFT JOIN chart_info ON chart_info.chartid = lu_chart_view.chart_id";

              $m1 = mysql_query($s1) or die("Query $s1 has passed away");

              $n1 = mysql_num_rows($m1);

              while ($row = mysql_fetch_array($m1)) {

                  $chartID = $row['chart_id'];

                  $viewName = $row['view_name'];

                  $type = $row['type'];

                  $label = $row['label'];

                  $vAxis = $row['vAxisLabelType'];

       

                  $tmpstr = "graph" . $chartID;

                  ${$tmpstr} = array();

       

                  $s1 = "SELECT * FROM $viewName";

                  $m1 = mysql_query($s1) or die("Query $s1 has passed away");

                  while ($row = mysql_fetch_array($m1)) {

                      $provs = array("value" => $row["Value"], "province" => $row["Province"]);

                  }

                  ${$tmpstr}[] = array("label" => $label, "vAxis" => $vAxis);

                  ${$tmpstr}[] = $provs;

                  $result[] = ${$tmpstr};

              }

              return $result;

          }

       

      How would I do the Flex part to get this information from PHP?  I am using Flash Builder 4.5.


      Thanks,

      Wesley

        • 1. Re: How to dynamically create charts
          relaxatraja Level 5

          Sample:

           

          var phpFile:String = "http://localhost/Raja/sendDataToServer.php";
            function callServer(e:MouseEvent):void
                  {
                       var urlRequest:URLRequest = new URLRequest(phpFile);

           

                      var urlParams:URLVariables = new URLVariables();
                       urlParams.country = "India";
                       urlParams.animal="Tiger";

           

                      urlRequest.method = URLRequestMethod.POST;
                       urlRequest.data = urlParams;

           

                      var loader:URLLoader = new URLLoader();
                       loader.addEventListener(Event.COMPLETE, serverResponse);
                       loader.load(urlRequest);
                   }

                  function serverResponse(e:Event):void

           

                  {

           

                      trace("loaded");

           

                      var loader:URLLoader = URLLoader(e.target);

           

                      var variables:URLVariables = new URLVariables(loader.data);

           

                      responseTxt.text = variables.returnValue;

           

                  }