title: Flot Pie Chart with PHP
body: <p>I tried to add load a Pie Chart dynamically using Flot Chart and PHP/MySQL.</p>
  
  <p>This is my javascript code</p>
  
  <pre><code> &lt;script id="source" language="javascript" type="text/javascript"&gt;
  
  
    function fetchData() {
     $.ajax({
        url:      "test.php",
        method:   "GET",
        dataType: "json",
        success:  function(series) {
           var data = [  series ];
           $.plot($("#graph1"), data, {
              pie: { 
                  show: true,
                  showLabel: true
              },
              legend: {
                  show: false 
              }
          });
        }
     });
  
     setTimeout(fetchData, 1000);
  }
  
  
  $(function () {
      $("#btn").click(function(){
      fetchData();                       
    });   
  
  });
  </code></pre>
  
  <p>This is my PHP Code</p>
  
  <pre><code>&lt;?php 
      include("db.php");
      $return_arr = array();
      $sql = mysql_query("SELECT item, COUNT(target) FROM counter WHERE type='video' and date BETWEEN '2011-02-21' and '2011-02-26' GROUP BY target ORDER BY id ASC");
      while($obj = mysql_fetch_object($sql)){
          $return_arr[] = $obj;   
      }
      echo json_encode($return_arr);
  ?&gt;
  </code></pre>
  
  <p>This is my button</p>
  
  <pre><code>&lt;input type="submit" value="click" id="btn"/&gt;
  </code></pre>
  
  <p>This is the array that I get when I click the button</p>
  
  <pre><code>[{"item":"Final 2010","COUNT(target)":"2"},{"item":"Semi Final 2009","COUNT(target)":"3"}]
  </code></pre>
  
  <p>When I click the button, it gives me this error:</p>
  
  <pre><code>An invalid or illegal string was specified" code: "12
  [Break On This Error] false 
  </code></pre>
  
  <p>and Even the pie chart is not loading. Can anybody tell me where did I made the wrong. </p>
  
  <p>When I check in firebug, the array is showing like this </p>
  
  <pre><code>[{"item":"Final 2010","COUNT(target)":"2"},{"item":"Semi Final 2009","COUNT(target)":"3"}]
  </code></pre>
  
  <p>But when I print it, it shows as [Object object][Object object], I think that would be the problem, anyone know how to fix it</p>
  
  <p>Thanks</p>