Somebody can help me. I'm new in php and highcharts. I tried to populate my chart using mysql and php, but when I tried to run it, the chart didn't appear, I only sse a blank web page. And there's no error appeared.
Her's my codes (sorry for messy code):
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="../../js/highcharts.js"></script>
<script src="../../js/modules/exporting.js"></script>
</head>
<body>
<?php
include "config.php";
$SQL1 = "SELECT * FROM pos";
$result1 = mysql_query($SQL1);
$data1 = array();
while ($row = mysql_fetch_array($result1)) {
$data1[] = $row['name'];
$data2[] = $row['Qty'];
}
?>
<script type="text/javascript">
$(function () {
$('#container').highcharts({
chart: {
type: 'column',
margin: [ 50, 50, 100, 80]
},
title: {
text: 'List of POS'
},
credits: {
enabled: false
},
xAxis: {
categories: [<?php echo join($data1, "','"); ?>],
labels: {
rotation: -45,
align: 'right',
style: {
fontSize: '13px',
fontFamily: 'Verdana, sans-serif'
}
}
},
yAxis: {
min: 0,
title: {
text: 'No. of Ticket'
}
},
legend: {
enabled: false,
layout: 'vertical',
backgroundColor: '#FFFFFF',
align: 'left',
verticalAlign: 'top',
x: 50,
y: 35,
floating: true,
shadow: true
},
tooltip: {
pointFormat: '<b>{point.y:.1f} tickets</b>',
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: 'Qty',
data: ['<?php echo join($data2, "','"); ?>'],
dataLabels: {
enabled: true,
rotation: -90,
color: '#FFFFFF',
align: 'right',
x: 4,
y: 10,
style: {
fontSize: '13px',
fontFamily: 'Verdana, sans-serif',
textShadow: '0 0 3px black',
}
}
}]
});
});
</script>
<div id="container" style="min-width: 500px; height: 400px; margin: 0 auto"></div>
</body>
</html>
And here's my config.php
<?php
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "pos";
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database");
mysql_select_db($mysql_database, $bd) or die("Could not select database");
?>
Please Try Example as below. I think it can help you
SQL Table
Here we have Create new table and insert some data in it. Now Data will look as below
index.php
setup.js
s will import data from
mysql
fromdata.php
and add to chart which is create previously in js.data.php
our chart is fully loaded .with mysql records and output will look li below
Output
its example of area chart, you can change type of chart by changing defaultSeriesType: 'area'
Click Here for more Example with source.
Even if this is an old thread, this might have nothing to do with Highcharts, I'v just noted the final phrase in your error message:
tipically has to do with a query that fails returning FALSE instead of a rowset. You should take a look at this related question.
Blank pages usually mean syntax errors. You should switch
error_reporting
on.The errors are in the use of your
echo
statements where you construct the json. The error is that you are missing semi colons in both theecho
statements.Replace
<?php echo join($data1, ',') ?>
with<?php echo join($data1, ','); ?>
Similarly for
$data2
:Replace
<?php echo join($data2, ',') ?>
with<?php echo join($data2, ','); ?>
Another improvement you could make in the following block:
Instead of executing query twice to build two arrays, you could get rid of one of the queries and build both the arrays from the same query result:
Note: The
php
mysql
extension is deprecated as of PHP 5.5.0, you should be using either MySQLi or PDO_MySQL.I think your supposed to have single quotes around this
Should be