我有一個js文件包含以下代碼:調用JS功能HTML
var BlankonDashboard = function() {
return {
// =========================================================================
// CONSTRUCTOR APP
// =========================================================================
init: function() {
BlankonDashboard.visitorChart();
},
// =========================================================================
// VISITOR CHART & SERVER STATUS
// =========================================================================
visitorChart: function() {
if($('#visitor-chart').length){
$.plot("#visitor-chart", [{
label: "Vente Année N",
color: "rgba(0, 177, 225, 0.35)",
data: [
["Jan", 420],
["Fév", 532],
["Mar", 367],
["Avr", 245],
["Mai", 674],
["Jui", 897],
["Juil", 745]
]
}, {
label: "Vente Année N-1",
color: "rgba(233, 87, 63, 0.36)",
data: [
["Jan", 362],
["Fév", 452],
["Mar", 653],
["Avr", 756],
["Mai", 670],
["Jui", 352],
["Juil", 243]
]
}], {
series: {
lines: { show: false },
splines: {
show: true,
tension: 0.4,
lineWidth: 2,
fill: 0.5
},
points: {
show: true,
radius: 4
}
},
grid: {
borderColor: "transparent",
borderWidth: 0,
hoverable: true,
backgroundColor: "transparent"
},
tooltip: true,
tooltipOpts: { content: "%x : %y" + " People" },
xaxis: {
tickColor: "transparent",
mode: "categories"
},
yaxis: { tickColor: "transparent" },
shadowSize: 0
});
}
},
};
}();
// Call main app init
BlankonDashboard.init();
visitorChart功能來繪製靜態數據的圖表,但我想這樣做動態使用PHP,我不知道如果我可以將php數據遷移到js文件(file.js),但是如果我可以將php數據遷移到這個功能(visitorChart),那我就會走了。
唉唉....你可以做一個AJAX調用JSON格式獲取數據後初始化圖表你得到的數據。看看這裏https://www.sitepoint.com/ajaxjquery-getjson-simple-example/ –
從PHP中吐出JavaScript或通過Ajax和JSON加載它。 – epascarello
但問題是我怎麼能調用這個函數,你可以在這個js文件中看到所有函數都變成了'var BlankonDashboard = function(){...}' –