I am new at d3 and learning alot. I have a little problem with updating my data, that i'm getting from a csv file.
I use setInterval() to update the data every second. When it removes and Insert the data again, it flickers for some milliseconds (the table goes away and a new table is generated). What am I doing wrong? How can i get rid of the flicker?
Thanks for Helping! :-)
Here my code:
<script type="text/javascript">
d3.text("data.csv", function(data) {
var parsedCSV = d3.csv.parseRows(data);
var container = d3.select("body")
.append("table")
.selectAll("tr")
.data(parsedCSV).enter()
.append("tr")
.selectAll("td")
.data(function(d) { return d; }).enter()
.append("td")
.text(function(d) { return d; });
});
var inter = setInterval(function() {
updateData();
}, 1000);
function updateData() {
d3.text("data.csv", function(data) {
var parsedCSV = d3.csv.parseRows(data);
var container = d3.select("body")
.append("table")
.selectAll("tr")
.data(parsedCSV).enter()
.append("tr")
.selectAll("td")
.data(function(d) { return d; }).enter()
.append("td")
.text(function(d) { return d; });
});
d3.select("body").selectAll("tr")
.remove()
}
</script>
Adding transition() to enter/exit/remove calls will resolve your flicker problem.