I am creating a simple Database driven Graph using Libraries from Codepen that are :
THIS and Highchart.js
I have a HTML File that simply displays the Chart, the main Data and processing is done through index.js file that contains the Static Values to draw the Graph. The file is :
$(function () {
var options = {
chart: {
renderTo: 'container'
},
subtitle: {
text: 'Subtitle'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
tickInterval: 4
},
/*** The following Values are needed to be fetched from DB which are now static */
series: [{
data: [89.9, 21.5, 16.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
},
chart = new Highcharts.Chart(options);
$('#redraw').click(function() {
console.log(chart.xAxis[0]);
chart.redraw();
});
});
Now I want to create PHP File that will Fetch the Data from the database and will send it to the JS File.
$test=mysql_query("select id from tbl_graph");
$rowtest=mysql_fetch_array($test);
Now what I want is the data that is fetched from the Database is needed to be send to the Index.js file so that the following static Values in index.js can be connected directly from the database.
series: [{
data: [89.9, 21.5, 16.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
I would appreciate any kind of help..