score:2

Have you tried to remove the chart at the top of the function?

so;

d3.selectAll('#chart3 svg').remove();

this would remove any instance of the chart before re drawing, a better approach might be to wrap inside an if statement to check if the svg exists first and then drawing it if it doesn't, using jquery this could be ;

if(!$('#chart3 svg').length > 0) {
    run code here...
}

Related Query