我有一个图表的静态脚本,如下所示:
<script type="text/javascript">
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer",
{
title:{
text: "Converting in Local Time"
},
axisX:{
title: "time",
gridThickness: 2,
interval:2,
intervalType: "hour",
valueFormatString: "HH:mm:ss",
labelAngle: -20
},
axisY:{
title: "distance"
},
data: [
{
type: "line",
dataPoints: [//array
{x: new Date("2016-03-28 15:28:30"), y: 26 },
{x: new Date( "2016-03-28 18:28:30" ), y: 38 },
{x: new Date( "2016-03-28 21:28:30" ), y: 43 }
]
},
{
type: "line",
dataPoints: [//array
{x: new Date("2016-03-28 14:28:30"), y: 20 },
{x: new Date( "2016-03-28 16:28:30" ), y: 38 },
{x: new Date( "2016-03-28 20:28:30" ), y: 13 }
]
}
]
});
chart.render();
}
</script>
上面的x和y数据是静态的,但我想动态显示它。我有循环数据如何将该循环放在x和y的静态值旁边。
我有动态数据:
<% for (var i=0; i < tags.length; i++)
{
console.log(tags[i]);
var data= points.points[tags[i]];
for (var n=0; n < data.length; n++)
{
console.log(data[n].dateTime);
console.log(data[n].value);
}
}
%>
我应该如何放置上面的dataPoints循环?