0
我试图使用nvd3和d3生成多个图表。我有适量的div。添加多个图表d3,nvd3使用for循环
如果我删除了forloop,那么我得到一个图表#chart1
。如果我把for循环,然后我得到一个图表只在#chart2
。
任何人都可以看到为什么?
for (var j = 1; j <= 2; j += 1) {
var s = '#chart' + j.toString() + ' svg';
console.log(s);
nv.addGraph(function() {
var chart = nv.models.lineChart();
chart.xAxis.axisLabel('Time step').tickFormat(d3.format(',r'));
chart.yAxis.axisLabel('eig(' + j.toString() + ')').tickFormat(d3.format('.02f'));
d3.select(s).datum(function() {
var sin = [], cos = [];
for (var i = 0; i < 100; i++) {
sin.push({
x : i,
y : Math.sin(i/10)
});
cos.push({
x : i,
y : .5 * Math.cos(i/10)
});
}
result = [];
result.push({
values : sin,
key : 'sin',
});
return result;
}).transition().duration(500).call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
}