javascript - dc.js clear all charts - Stack Overflow

I have a html page with 5 dc.js charts.I would like to clear all the charts (pletely remove them from t

I have a html page with 5 dc.js charts.

I would like to clear all the charts (pletely remove them from the page) given a certain event.

something like:

dc.clearAll();

I checked the API's and such a method does not exist.

I implemented a workaround with jquery:

$('#chart1').empty();
$('#chart2').empty();
$('#chart3').empty();
$('#chart4').empty();
$('#chart5').empty();

The workaround works but i was wondering if there was a cleaner way to do it, preferably with the API.

I have a html page with 5 dc.js charts.

I would like to clear all the charts (pletely remove them from the page) given a certain event.

something like:

dc.clearAll();

I checked the API's and such a method does not exist.

I implemented a workaround with jquery:

$('#chart1').empty();
$('#chart2').empty();
$('#chart3').empty();
$('#chart4').empty();
$('#chart5').empty();

The workaround works but i was wondering if there was a cleaner way to do it, preferably with the API.

Share Improve this question asked Apr 15, 2014 at 10:44 Amr H. Abd ElmajeedAmr H. Abd Elmajeed 1,52115 silver badges41 bronze badges 1
  • You could also do it with d3 if you don't want the extra dependency of jquery - d3.selectAll("svg").remove(). – elsherbini Commented Apr 22, 2014 at 16:39
Add a ment  | 

2 Answers 2

Reset to default 5

If when you create the charts you name them, you can use the api like so:

chartOne.resetSvg()
chartTwo.resetSvg()

etc. This will leave behind an empty <svg> tag in the div.

d3.selectAll("svg").remove() worked for me.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745294529a4621059.html

相关推荐

  • javascript - dc.js clear all charts - Stack Overflow

    I have a html page with 5 dc.js charts.I would like to clear all the charts (pletely remove them from t

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信