Json data is not displaying on the highcharts graphs. :( Please help.. Used getJSON that is not parsing at all. .post works shows msg.. dont know how to resolve..My graph code..
$(function () {
var chart;
$.post("data.php", function(json)
{
//alert("Data Loaded: " + json);
chart = new Highcharts.Chart({
chart: {
renderTo: 'container1',
type: 'area'
},
yAxis: {
type: 'double',
min: 0
},
xAxis: {
type: 'datetime',
labels: {
formatter: function () {
return Highcharts.dateFormat('%b %y', this.value);
},
dateTimeLabelFormats: {
month: '%b \'%y',
year: '%Y'
}
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: json
});
});
});
This is my php code.. to get the json data
$mysql_connect = mysql_connect($db_host, $db_user, $db_pword, $db_name);
$query = "Select DATE_FORMAT(`timestamp`,'%Y,%m,%d') as date, Count(*) as frequency from table group by date order by date,frequency asc";
if (!$mysql_connect) die("unable to connect to database: " . mysql_error());
@mysql_select_db($db_name) or die( "Unable to select database");
$result = mysql_query($query);
$response = array();
if($result === FALSE)
{
die(mysql_error());
}
echo "[";
$results = array();
while($row=mysql_fetch_array($result))
{
$results[] = "[Date.UTC(".$row ['date']."),".$row['frequency']."]";
}
echo implode(',',$results);
echo "]";
mysql_close($mysql_connect);
mysql_*functions are no longer maintained and shouldn't be used in any new codebase. It is being phased out in favor of newer APIs. Instead you should use prepared statements with either PDO or MySQLi.