I am using d3.js to make data visualization but I am not a JavaScript programmer so I wrote something like the following
for(var i =0;i<6;i++){
setTimeout(function(){
var in = data[0][i];
slate(" + margin.left + "," + margin.top + ")");
var svg = d3.select("#clustering").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 + ")");
svg.append("rect")
.attr("width", width)
.attr("height", height);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis);
var color = d3.scale.category10();
refreshGraph();
},1000);
}
/*
* function displaying data on svg
* called every time data change
*/
var refreshGraph = function(){
// removing all previously drawn dots
svg.selectAll(".dot")
.data(instruments)
.exit()
.remove();
}
But I got this error Uncaught Reference Error: svg is not defined
I know the function refreshGraph
can not see the var svg
, but I don't know how to fix this.
Thank you for your help.