title: Having trouble drawing google piechart using data from MYSQL database
body: <p>I have been creating a piechart on dashboard for the user. I have tried following code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
   // Load the Visualization API and the piechart package.
  google.load('visualization', '1', {'packages':['corechart']});
  
  // Set a callback to run when the Google Visualization API is loaded.
  google.setOnLoadCallback(drawChart);
  
  function drawChart() {
    var jsonData = $.ajax({
        url: "getData.php",
        dataType:"json",
        async: false
        }).responseText;
  
    // Create our data table out of JSON data loaded from server.
    var data = new google.visualization.DataTable(jsonData);
  
    // Instantiate and draw our chart, passing in some options.
    var chart = new google.visualization.PieChart(document.getElementById('piechart'));
    chart.draw(data, {width: 400, height: 240});
  }
  
  
  &lt;/script&gt;
  </code></pre>
  
  <p>getData.php</p>
  
  <pre><code>$sent = mysqli_query($con,"SELECT name FROM table_name WHERE user_id='$user_id'");
  $num_rows_sent = mysqli_num_rows($sent);
  
  
  $viewed = mysqli_query($con,"SELECT viewed FROM table_name WHERE user_id='$user_id' AND viewed= 1 ");
  $num_rows_viewed= mysqli_num_rows($viewed);
  
  
  $accepted = mysqli_query($con,"SELECT accepted FROM table_name WHERE user_id='$user_id' AND accepted= 1 ");
  $num_rows_accepted= mysqli_num_rows($accepted);
  
  
  $declined = mysqli_query($con,"SELECT declined FROM table_name WHERE user_id='$user_id' AND declined= 1 ");
  $num_rows_declined= mysqli_num_rows($declined);
  
  
  $suggest = mysqli_query($con,"SELECT In_Discussion FROM table_name WHERE user_id='$user_id' AND In_Discussion= 1 ");
  $num_rows_suggest= mysqli_num_rows($suggest);
  
  $results = array(
  "cols" =&gt; array(
  
  
      array("label" =&gt; "sent", "type" =&gt; "string"),
      array("label" =&gt; "viewed", "type" =&gt; "number"),
      array("label" =&gt; "accepted", "type" =&gt; "number"),
      array("label" =&gt; "declined", "type" =&gt; "number"),
      array("label" =&gt; "In_Discussion", "type" =&gt; "number"),
  ),
  "rows" =&gt; array()
  );
  
  $results["rows"][] = array("c" =&gt; array(
  
      array("v" =&gt; $num_rows_sent,"f"=&gt;"sent" ),
      array("v" =&gt; $num_rows_viewed,"f"=&gt;"viewed"),
      array("v" =&gt; $num_rows_accepted,"f"=&gt;"accepted"),
      array("v" =&gt; $num_rows_declined,"f"=&gt;"declined"),
      array("v" =&gt; $num_rows_suggest,"f"=&gt;"In Discussion"),
  ));
  
  $json = json_encode($results,JSON_NUMERIC_CHECK);
  echo $json;
  </code></pre>
  
  <p>I am getting JSON like dis:</p>
  
  <pre><code>{
      "cols":[
              {"label":"sent","type":"string"},
              {"label":"viewed","type":"number"},
              {"label":"accepted","type":"number"},
              {"label":"declined","type":"number"},{"label":"In_Discussion","type":"number"}
             ],
  
     "rows":[
             { "c":
                  [
                     {"v":4,"f":"sent"},{"v":4,"f":"viewed"},{"v":1,"f":"accepted"},{"v":0,"f":"declined"},{"v":2,"f":"In Discussion"}
  
                  ]
             }
           ]
  }
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/7AzNr.png" rel="nofollow">I am getting this chart as output</a></p>
  
  <p><a href="http://i.stack.imgur.com/RmOWB.png" rel="nofollow">Desired Chart</a></p>
  
  <p>How can I output the desired chart using the data above??</p>