试图让这个脚本每隔一秒重新加载一次随机变量。我得到的只是第一组数据,chart.render 似乎只在它没有嵌套在函数中时才起作用。似乎是“工作”功能被破坏了。我为折线图尝试了 canvasjs 解决方案,它也不起作用。有任何想法吗?
<!DOCTYPE HTML>
<html><head> <meta http-equiv="content-type" content="text/html; charset=UTF8">
<script type="text/javascript" src="canvasjs.min.js"></script>
<script type="text/javascript">
var f86,f810,f814,f816,d96,d910,d914,d916,d86,d810,d814,d816,c46,c410,c414,c416;
f86 = Math.floor(Math.random() * 10) + 80 +1;
f810 = Math.floor(Math.random() * 10) + 80 +1;
f814 = Math.floor(Math.random() * 10) + 80 +1;
f818 = Math.floor(Math.random() * 10) + 80 +1;
d96 = Math.floor(Math.random() * 10) + 80 +1;;
d910 = Math.floor(Math.random() * 10) + 80 +1;
d914 = Math.floor(Math.random() * 10) + 80 +1;
d918 = Math.floor(Math.random() * 10) + 80 +1;
d86 = Math.floor(Math.random() * 10) + 80 +1;
d810 = Math.floor(Math.random() * 10) + 80 +1;
d814 = Math.floor(Math.random() * 10) + 80 +1;
d818 = Math.floor(Math.random() * 10) + 80 +1;
c46 = Math.floor(Math.random() * 10) + 80 +1;
c410 = Math.floor(Math.random() * 10) + 80 +1;
c414 = Math.floor(Math.random() * 10) + 80 +1;
c418 = Math.floor(Math.random() * 10) + 80 +1;
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer",
{
axisX:{tickThickness: 1,lineThickness: 1},
toolTip:{enabled: false},
axisY: {includeZero: false,suffix: "C",minimum: 0,maximum: 123,tickThickness: 1,lineThickness: 1,gridThickness: 1},
data:[
{
type: "bar",indexLabel: "{y} C ",showInLegend: true,name: "6'",color: "#8080E6",indexLabelPlacement: "inside",indexLabelFontColor: "white",
dataPoints: [{ y: c46, label: "C4"},{ y: d86, label: "D8"},{ y: d96, label: "D9"},{ y: f86, label: "F8"}]
},
{
type: "bar",indexLabel: "{y} C ",showInLegend: true,name: "10'",color: "#3333D6",indexLabelPlacement: "inside",indexLabelFontColor: "white",
dataPoints: [{ y: c410, label: "C4"},{ y: d810, label: "D8"},{ y: d910, label: "D9"},{ y: f810, label: "F8"}]
},
{
type: "bar",indexLabel: "{y} C ",showInLegend: true,name: "14'",color: "#0000B8",indexLabelPlacement: "inside",indexLabelFontColor: "white",
dataPoints: [{ y: c414, label: "C4"},{ y: d814, label: "D8"},{ y: d914, label: "D9"},{ y: f814, label: "F8"}]
},
{
type: "bar",indexLabel: "{y} C ",showInLegend: true,name: "18'",color: "#000066",indexLabelPlacement: "inside",indexLabelFontColor: "white",
dataPoints: [{ y: c418, label: "C4"},{ y: d818, label: "D8"},{ y: d918, label: "D9"},{ y: f818, label: "F8"}]
}
]
});
chart.render();
}
function work() {
f86++;
f810 = Math.floor(Math.random() * 10) + 80 +1;
f814 = Math.floor(Math.random() * 10) + 80 +1;
f818 = Math.floor(Math.random() * 10) + 80 +1;
d96 = Math.floor(Math.random() * 10) + 80 +1;;
d910 = Math.floor(Math.random() * 10) + 80 +1;
d914 = Math.floor(Math.random() * 10) + 80 +1;
d918 = Math.floor(Math.random() * 10) + 80 +1;
d86 = Math.floor(Math.random() * 10) + 80 +1;
d810 = Math.floor(Math.random() * 10) + 80 +1;
d814 = Math.floor(Math.random() * 10) + 80 +1;
d818 = Math.floor(Math.random() * 10) + 80 +1;
c46 = Math.floor(Math.random() * 10) + 80 +1;
c410 = Math.floor(Math.random() * 10) + 80 +1;
c414 = Math.floor(Math.random() * 10) + 80 +1;
c418 = Math.floor(Math.random() * 10) + 80 +1;
chart.render();
setTimeout('work()', 100);
}
work();
</script>
</head>
<body><br>
<div style="width: 850px; overflow: auto; padding: 1em; margin: auto; float:center">
<div id="chartContainer" style="height: 400px; width: 500px; float:left"></div>
</div>
</body>
</html>