Answer from here : https://stackoverflow.com/a/12863675/894470 is how to assign array to variable.
I'm getting my data from php but when I echo it inside javscript like example below my chart wont draw.
var month_data= [<?php echo json_encode($lol); ?>];
but I can show alert and see all my data no problem like below:
If I copy the text from alert and paste it in array like below:
var month_data= [{month: '2014-01', KFC: 0, PizzaHut: 1},{month: '2014-03', KFC: 2, PizzaHut: 1},{month: '2014-04', KFC: 1, PizzaHut: 0},{month: '2014-05', KFC: 0, PizzaHut: 1},{month: '2014-07', KFC: 1, PizzaHut: 0},{month: '2014-10', KFC: 42, PizzaHut: 42}];
my chart will draw. What is wrong here??
UPDATE: My query:
$lol = array();
while ($row = mysqli_fetch_array($result)) {
$lol[] = "{month: '". $row['year'] ."-". $row['month'] ."', KFC: ". $row['kfc'] .", PizzaHut: ". $row['pizzahut'] ."}";
}
and I'm using Morris.js
: http://morrisjs.github.io/morris.js/ to generate my chart.