javascript - d3.js dynamic data reload possibly related to exit().remove() -
i have implemented d3 visualization http://bl.ocks.org/4745936 , loaded dynamic info instead of .tsv
in case, 1 time server passes new info selector, sec chart gets rendered under first one, instead of modifying contents of existing graph.
i believe has append
method.
var svg = d3.select(selector).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 + ")");
so tried adding other exit().remove()
methods legend , cities variables right after append('g');
javascript console says exit()
method not exist @ point.
i sense have wrong approach, how update existing graph this? having sec , 3rd graph generated alongside previous ones not outcome wanted @ all
you're right append method adding new svg element every time. prevent duplicate charts need check if svg element exists already. seek @ begining:
var svg = d3.select("#mycontainer > svg") if (svg.empty()) svg = d3.select(selector).append("svg"); ...
as stated in exit() docs, this method defined on selection returned info operator. create sure you're calling exit on selection returned .data(..)
.
javascript d3.js
No comments:
Post a Comment