PHP MySQL Google Chart JSON - Complete Example

匿名 (未验证) 提交于 2019-12-03 02:44:02

问题:

I have searched a lot to find a good example for generating a Google Chart using MySQL table data as the data source. I searched for a couple of days and realised that there are few examples available for generating a Google Chart (pie, bar, column, table) using a combination of PHP and MySQL. I finally managed to get one example working.

I have previously received a lot of help from StackOverflow, so this time I will return some.

I have two examples; one uses Ajax and the other does not. Today, I will only show the non-Ajax example.

Usage:

    Requirements: PHP, Apache and MySQL      Installation:        --- Create a database by using phpMyAdmin and name it "chart"       --- Create a table by using phpMyAdmin and name it "googlechart" and make            sure table has only two columns as I have used two columns. However,            you can use more than 2 columns if you like but you have to change the            code a little bit for that       --- Specify column names as follows: "weekly_task" and "percentage"       --- Insert some data into the table       --- For the percentage column only use a number            ---------------------------------           example data: Table (googlechart)           ---------------------------------            weekly_task     percentage           -----------     ----------           Sleep           30           Watching Movie  10           job             40           Exercise        20     


PHP-MySQL-JSON-Google Chart Example:

     'Weekly Task', 'type' => 'string'),     array('label' => 'Percentage', 'type' => 'number')  );  $rows = array(); while($r = mysql_fetch_assoc($sth)) {     $temp = array();     // the following line will be used to slice the Pie chart     $temp[] = array('v' => (string) $r['Weekly_task']);       // Values of each slice     $temp[] = array('v' => (int) $r['percentage']);      $rows[] = array('c' => $temp); }  $table['rows'] = $rows; $jsonTable = json_encode($table); //echo $jsonTable; ?>                                          


PHP-PDO-JSON-MySQL-Google Chart Example:

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!