How to create highchart by chart using php

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>
<title>Stacked column chart with data from MySQL using Highcharts</title>
http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js

$(document).ready(function() {
var options = {
chart: {
renderTo: ‘container’,
type: ‘column’,
marginRight: 130,
marginBottom: 25
},
title: {
text: ‘Project Requests’,
x: -20 //center
},
subtitle: {
text: ”,
x: -20
},
xAxis: {
categories: []
},
yAxis: {
title: {
text: ‘Requests’
},
plotLines: [{
value: 0,
width: 1,
color: ‘#808080’
}]
},
tooltip: {
formatter: function() {
return ‘‘+ this.series.name +’
‘+
this.x +’: ‘+ this.y;
}
},
legend: {
layout: ‘vertical’,
align: ‘right’,
verticalAlign: ‘top’,
x: -10,
y: 100,
borderWidth: 0
},
plotOptions: {
column: {
stacking: ‘normal’,
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || ‘white’
}
}
},
series: []
}

$.getJSON(“data.php”, function(json) {
options.xAxis.categories = json[0][‘data’];
options.series[0] = json[1];
options.series[1] = json[2];
options.series[2] = json[3];
chart = new Highcharts.Chart(options);
});
});

http://code.highcharts.com/highcharts.js
http://code.highcharts.com/modules/exporting.js
</head>
<body>

</body>
</html>

 

Sample Data.php
$query = mysql_query(“SELECT month, wordpress, codeigniter, highcharts FROM project_requests”);

$category = array();
$category[‘name’] = ‘Month’;

$series1 = array();
$series1[‘name’] = ‘WordPress’;

$series2 = array();
$series2[‘name’] = ‘CodeIgniter’;

$series3 = array();
$series3[‘name’] = ‘Highcharts’;
while($r = mysql_fetch_array($query)) {
$category[‘data’][] = $r[‘month’];
$series1[‘data’][] = $r[‘wordpress’];
$series2[‘data’][] = $r[‘codeigniter’];
$series3[‘data’][] = $r[‘highcharts’];
}

$result = array();
array_push($result,$category);
array_push($result,$series1);
array_push($result,$series2);
array_push($result,$series3);
print json_encode($result, JSON_NUMERIC_CHECK);

mysql_close($con);
?>

 

Source: http://blueflame-software.com/demo/stacked-column-chart-with-data-from-mysql-using-highcharts/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s