I am having problem when generating 15 line-chars from 15 .csv files by using a for loop. Instead of locating each graph in a different div, 15 graphs all overlapped in the last div.
Thank you in advance.
for (var i = 0; i<15; i++) {
var svg = d3.select("#graph_"+i)
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// Get the data
d3.csv(folder.toString()+"/"+i+".csv", function(error, data) {
data.forEach(function(d) {
d.x = +d.x;
d.y = +d.y;
});
// Scale the range of the data
x.domain(d3.extent(data, function(d) { return d.x; }));
y.domain([0, d3.max(data, function(d) { return d.y; })]);
// Add the valueline path.
svg.append("path")
.attr("class", "line")
.attr("d", valueline(data));
// Add the X Axis
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
// Add the Y Axis
svg.append("g")
.attr("class", "y axis")
.call(yAxis);
});
}
Aucun commentaire:
Enregistrer un commentaire