title: Create PieChart with google chart api and php
body: <p>I'm kinda new to google chart api, and still wiping the dust out my php knowledge, so maybe someone can help with this (IMO) basic question...</p>
  
  <p>So I have this php class wich queries data from server and should post it back to my page. There is a working Line Chart in it, as you can see at the snippet below:</p>
  
  <pre><code>$rowdata = array();
              $i=0;
              $_POST['from'] = str_replace("/","-",$_POST['from']);
              $_POST['to'] = str_replace("/","-",$_POST['to']);
  
              $cur_date = $_POST['from'];
  
              $sql =  "SELECT DATE(entered),
                             COUNT(*) AS totalaccounts,
                             SUM(CASE WHEN facebook_username != '' THEN 1 ELSE 0 END) AS facebook,
                             SUM(CASE WHEN facebook_username = '' THEN 1 ELSE 0 END) AS standard
                      FROM Account
                      WHERE entered BETWEEN '". $_POST['from'] ."' AND '". $_POST['to'] ."'
                      GROUP BY DATE(entered)";
  
              $result = $dbMain-&gt;query($sql);
              $rows = tratarDadosParaGrafico($result);
  
              $return = json_encode(array('cols' =&gt; $cols, 'rows' =&gt; $rows));
  
              $data = array(
                  'cols' =&gt; array(
                      array('id' =&gt; '', 'label' =&gt; 'Date', 'type' =&gt; 'string'),
                      array('id' =&gt; '', 'label' =&gt; 'Total Accounts', 'type' =&gt; 'number'),
                      array('id' =&gt; '', 'label' =&gt; 'Total Accounts (Facebook)', 'type' =&gt; 'number'),
                      array('id' =&gt; '', 'label' =&gt; 'Total Accounts (Non Facebook)', 'type' =&gt; 'number')
                  ),
                  'rows' =&gt; $rows
              );
  
  
              $chart = new Chart('LineChart');
              $options = array('title' =&gt; 'Accounts');
              $chart-&gt;load(json_encode($data));
              echo $chart-&gt;draw('rchart', $options);
  </code></pre>
  
  <p>What I was trying to do was use the same query result ($data) to populate another chart, this one a pie chart... So I simply pasted the last 4 lines of code, changing the parameter when creating a new instance of Chart:</p>
  
  <pre><code>$chart = new Chart('PieChart');
              $options = array('title' =&gt; 'Accounts');
              $chart-&gt;load(json_encode($data));
              echo $chart-&gt;draw('pchart', $options);
  </code></pre>
  
  <p>After this, I close the php tag and use 2 divs to show my charts...</p>
  
  <pre><code>&lt;div id="rchart"&gt;&lt;/div&gt;
          &lt;div id="pchart"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Everything here comes from this index.php class, I haven't seen html files at all... What happens is I can see the pie chart right below the line chart, but <strong>it comes with no data within</strong>, i.e., the whole chart is grey and labeled as "Other"</p>
  
  <p>What may I've done wrong? Thanks in advance!</p>
  
  <p>[EDIT]
  Let's say I want a Pie Chart with only 2 slices, why the code below doesn't works? (I get "Cannot read property '1' of undefined" error)</p>
  
  <pre><code>$data = array(
                  'cols' =&gt; array(
                      array('label' =&gt; 'Pie slice labels', 'type' =&gt; 'string'),
                      array('label' =&gt; 'Pie slice values', 'type' =&gt; 'number')
                  ),
                  'rows' =&gt; array(
                      array('v' =&gt; intval($facebook_accounts[0]), 'type' =&gt; 'int'),
                      array('v' =&gt; intval($default_accounts[0]), 'type' =&gt; 'int')
                  )
              );
              $chart = new Chart('PieChart');
              $options = array('title' =&gt; 'Accounts');
              $chart-&gt;load(json_encode($data));
              echo $chart-&gt;draw('piechart', $options);
  </code></pre>
  
  <p>[EDIT] Maybe this can help you helping me :)
  <a href="https://groups.google.com/forum/#!topic/google-visualization-api/Wi_WOVOgzG8" rel="nofollow noreferrer">https://groups.google.com/forum/#!topic/google-visualization-api/Wi_WOVOgzG8</a></p>
  
  <p><a href="https://stackoverflow.com/questions/17590539/creating-pie-char-from-mysql-database-using-php-and-google-charts?rq=1">Creating Pie char from mysql database using php and google charts</a></p>