Here we will learn How to Bind Google Column Chart in PHP and Mysql
What is Column Chart
A column chart is a vertical bar chart rendered in the browser using SVG or VML , whichever is appropriate for the user’s browser. Like all Google charts, column charts display tooltips when the user hovers over the data. For a horizontal version of this chart, see the bar chart .
Create a Table and Put Data according to this table.
1
CREATE
TABLE
`chart_data_column` (
2
`class`
varchar
(40)
NOT
NULL
,
3
`girl`
int
(3)
NOT
NULL
,
5
) ENGINE=InnoDB
DEFAULT
CHARSET=utf8;
11
INSERT
INTO
`chart_data_column` (`class`, `girl`, `boy`)
VALUES
12
(
'First Standard'
, 44, 52),
13
(
'Second Standard'
, 68, 65),
14
(
'Third Standard'
, 44, 52),
15
(
'Fourth Standard'
, 78, 55),
16
(
'Fifth Standard'
, 44, 52),
17
(
'Six Standard'
, 98, 75);
1
<!doctype html
public
"-//w3c//dtd html 3.2//en"
>
8
$host_name
=
"localhost"
;
16
$connection
= mysqli_connect(
$host_name
,
$username
,
$password
,
$database
);
18
if
(
$stmt
=
$connection
->query(
"SELECT class,girl,boy FROM chart_data_column "
)){
19
$php_data_array
= Array();
20
while
(
$row
=
$stmt
->fetch_row()) {
21
$php_data_array
[] =
$row
;
24
echo
$connection
->error;
27
var
my_2d =
".json_encode($php_data_array)."
31
<h1>Bind Google Column Chart in PHP
and
Mysql with Source Code</h1>
32
<div id=
"chart_div"
></div>
36
<script type=
"text/javascript"
>
39
google.charts.load(
'current'
, {packages: [
'corechart'
,
'bar'
]});
40
google.charts.setOnLoadCallback(drawChart);
42
function
drawChart() {
45
var
data =
new
google.visualization.DataTable();
46
data.addColumn(
'string'
,
'Class'
);
47
data.addColumn(
'number'
,
'Total Boy'
);
48
data.addColumn(
'number'
,
'Total Girl'
);
49
for
(i = 0; i < my_2d.length; i++)
50
data.addRow([my_2d[i][0], parseInt(my_2d[i][1]),parseInt(my_2d[i][2])]);
52
title:
'Student Details'
,
53
hAxis: {title:
'Month'
, titleTextStyle: {color:
'#333'
}},
57
var
chart =
new
google.charts.Bar(document.getElementById(
'chart_div'
));
58
chart.draw(data, options);
Bind Google Column Chart in PHP and Mysql with Source Code
Bind Google Column Chart in PHP and Mysql
About Post Author
Continue Reading