title: Format data served from MySql via PHP PDO to feed Googe Charts on the Visualization API
body: <p>I need to generate decision trees from a MYSQL v 5.6 table, queried with PHP  PDO.  I have a nice query which gives the data required, however I can't find the correct format to parse data to the Google API.</p>
  
  <p>I searched and found a myriad of articles on how to format data to feed Google Charts.  However the common denominator is the use of the infamous and deprecated mysql_query class to fetch data, and some addrow method which I found quite strange and UnClean.</p>
  
  <p>I'm asking how should I format the json output in order to porperly feed the API.  At the moment I query the data, json encode it using PHP's <strong>json_encode</strong>, and get the data properly via <strong>AJAX</strong>.  Indeed my console shows that the data is properly read by the browser,  however I know there is a format issue.  </p>
  
  <p>Unfortuantely tha google visualization API doesn't give me info on where the error could be.  I just received this message:</p>
  
  <pre><code>Invalid format in explicit format: column #0 must be of type 'number'
  </code></pre>
  
  <p>Well this is a sample of data that the google javascript receives:</p>
  
  <pre><code>[{"id":"1","elemento":"CLIO","parent":"0","size":306},  {"id":"2","elemento":"LOGAN","parent":"0","size":431},  {"id":"3","elemento":"SANDERO","parent":"0","size":335},    
  </code></pre>
  
  <p>On the other way,  I'm following strictly the Google visualization guidelines to use data from external data sources:
  <a href="https://developers.google.com/chart/interactive/docs/php_example?csw=1" rel="nofollow">Populating Data Using Server-Side Code</a></p>
  
  <p>and specifically the chart that I need to render <a href="https://developers.google.com/chart/interactive/docs/gallery/wordtree#full" rel="nofollow">Wordtrees</a>, which uses and <strong>arrayToDataTable</strong> method to format properly the data.</p>
  
  <p>What should I correct in order to get and/or read the proper formatted json string of data?  Please keep in mind the previous example of actual data which uses:</p>
  
  <pre><code>echo json_encode($data);  
  </code></pre>
  
  <p>to JSON format the query output.  Should I construct a table?  How to do it in a proper, clean and modern way,  not the mysql_query iteration.</p>
  
  <p>Thanks for your time and collaboration.</p>