我已经阅读了这里试图获取从 PHP 传递到 javascript 的数值的几乎所有问题。如您所见,我成功生成了随机数并且效果很好,但是当我尝试将变量传递给 graph.update 函数时,即使两个变量都确实具有根据 firebug 的值(分别为 14060116 和 0,这是正确的)他们没有进入更新功能......有什么想法吗?如果有帮助,这是完整的脚本!
<script>
(function () {
function createCanvas(divName) {
var div = document.getElementById(divName);
var canvas = document.createElement('canvas');
div.appendChild(canvas);
if (typeof G_vmlCanvasManager != 'undefined') {
canvas = G_vmlCanvasManager.initElement(canvas);
}
var ctx = canvas.getContext("2d");
return ctx;
}
var ctx = createCanvas("graphDiv1");
var upld = <?php echo json_encode($dirupld[0]); ?>;
var upldred = <?php echo json_encode($dirupldred[0]); ?>;
var graph = new BarGraph(ctx);
graph.maxValue = 30;
graph.margin = 10;
graph.width = 450;
graph.height = 200;
graph.colors = ["#49a0d8", "#d353a0"];
graph.xAxisLabelArr = ["Traditional", "Duplicate Reduced"];
graph.update([upld, upldred]);
//graph.update([Math.random() * 30, Math.random() * 30]);
}());
</script>
不确定我在哪里失去了价值观?Firebug 报告以下内容
var upld = 14060116;
var upldred = 0;
graph.update([upld, upldred]);