Using PDO the main file to display column / bar Chart.
Using CSV (Comma Separated Value) file :
Reading CSV file by using fgetcsv() and display chart.
Comma separated value ( csv ) file with data.
Download Zip file at end of this tutorial.
Column Chart : Orientation is vertical Bar Chart : Orientation is horizontal
Column & Bar Chart with data from MySQL database table using PHP pdo and google chart library
Sample column Chart in html
Before displaying records in a table we have created an array in PHP ( $php_data_array). While displaying the records in a table we store each record inside the PHP array.
$php_data_array = $row; // Adding to array
After displaying all the records in a table we have the $php_data_array with all the data collected from MySQL table. We can display the Json string like this.
We created the PHP array $php_data_array by using MySQL database as source. Once the php array is created the rest of the code remain same. Below you can find code to create this $php_data_array by using csv file as source.
var chart =
var chart =
Using CSV file as data source
Once the php aray $php_data_array is created the rest of the code remain same. Here we are reading the chart_data_column.csv file to create the $php_data_array. Once the array is created same code can be used. Zip file below contains the chart_data_column.csv file as data source and the index-csv.php file to display the chart.
We used fgetcsv() to read csv file