I am creating a div
container which I then fill with a svg
var someContainer = d3.select("#abc")
.append("div")
.classed("svg-container", true)
.append("svg")
.attr("preserveAspectRatio", "xMinYMin meet")
.attr("viewBox","0 0 400 100")
.classed("svg-content-responsive", true)
.selectAll("circle")
.data(someScale.range());
I then append my data to it
someContainer.remove();
someContainer.enter()
.append("circle")
.attr("x", function (d, i) {
return i * 2;
})
.attr("y", 5)
.attr("height", 15)
....;
However, whenever I update the content of the svg
, i.e. append new circles, a completely new div-container
and svg-container
gets created. That leaves me with the old data visually staying in its place and right on the bottom (meaning, 100px further down) there is the new data. Its basically a visual copy, but with the new data... Whenever I udpate my data, a new coy gets replaced under the old one, leaving me with n graphics.
Here is the css
that styles the relative container and makes sure, it scales when the window size is changed. Source: Resize svg when window is resized in d3.js */
.svg-container {
display: inline-block;
position: relative;
width: 100%;
padding-bottom: 50%; /* aspect ratio */
vertical-align: top;
overflow: hidden;
}
.svg-content-responsive {
display: inline-block;
position: absolute;
top: 10px;
left: 0;
}
Any ideas what I am doing wrong?