score:1

Accepted answer

Why don't you want to use unique element with id for your chart?

var canvas = d3.select("body svg:svg");
    if(!svg){
canvas = d3.select("body")

Try to change it to something like

var canvas = d3.select("#yourId svg:svg");
    if(!svg){
canvas = d3.select("#yourId")

Also add <div id='yourId'></div> tag to a tab, where your chart should be

score:0

Try removing svg before rendering another svg

d3.select("svg").remove();

Related Query

More Query from same tag