I have .php file and I have js file. I am trying to make bar chart. Now I have selected some data to my database. and now I don't know how can I get data from .php file to .js file.
I have this code:
//.js file
var data, options;
// replace this data with my selected data
data = {
labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
series: [
[19, 29, 28, 44, 39, 48, 54],
]
};
options = {
height: 300,
showArea: true,
showLine: true,
showPoint: true,
fullWidth: true,
axisX: {
showGrid: false
},
lineSmooth: false,
};
new Chartist.Line('#headline-chart', data, options);
/PHP FILE/
$chart6 = $controller->runQuery("SELECT DATE(pay_date) `DATE`, SUM(amount) daily_amount, DATE_FORMAT(pay_date,'%a') DAYNAME FROM tbl_paid WHERE DATE(pay_date) BETWEEN DATE(:today) - INTERVAL 1 WEEK AND DATE(:today) GROUP BY DATE(pay_date);");
$chart6->execute(array(":today"=>$today));
while($fetch = $chart6->fetch(PDO::FETCH_ASSOC))
{
$data ="{labels:".$fetch['DATE']."-".$fetch['DAYNAME']." series:".$fetch['daily_amount']."}";
}
json_encode($array)<script>tag and pass that variable to chart config