I am a beginner as you can see. Would like to learn how to pass value from MySQL database into a Bootstrap chart module. I have basic knowledge in PHP but do not know how to work with PHP in a .JS file. Please refer me to a tutorial or another similar topic with answers. Thank you.
I tried to embed the PHP code section into the part 'data' of variable 'data', as you can see.
(function(window, document, $, undefined) {
'use strict';
$(initFlotLine)
function initFlotLine() {
var data = [{
"label": "Sales",
"color": "#5ab1ef",
"data": <?php echo json_encode($data); ?> // my silly attempt
}, ];
var options = {
series: {
lines: {
show: true,
fill: 0.01
},
points: {
show: true,
radius: 4
}
},
grid: {
borderColor: '#eee',
borderWidth: 1,
hoverable: true,
backgroundColor: '#fcfcfc'
},
tooltip: true,
tooltipOpts: {
content: function(label, x, y) { return x + ' : ' + y; }
},
xaxis: {
tickColor: '#eee',
mode: 'categories'
},
yaxis: {
// position: 'right' or 'left'
tickColor: '#eee'
},
shadowSize: 0
};
var chart = $('.chart-line');
if (chart.length)
$.plot(chart, data, options);
}
})(window, document, window.jQuery);