alisabzevari
alisabzevari

Reputation: 8136

dcjs, crossfilter - How to completely dispose a chart

I have created a dashboard with dc.js. In my dashboard, there is a check box which allows the user to toggle the dashboard behavior between count and amount. To do this I have recreated the crossfilter with a different reduceSum for all of my groups. (Although, I do not know if this is the proper way to do this or not.) After recreating crossfilter I have to recreate dc.js charts as well.

I think this could lead to some memory leaks and performance issues because I have defined the filtered event for all of my charts and don't know how to turn off that event. Also after checking and unchecking the checkbox page slows down.

My question: Is there another way to completely change the crossfilter data without recreating the dc.js charts? If not, how does one properly remove dc.js charts to avoid memory leaks and performance problems?

Upvotes: 0

Views: 806

Answers (1)

Gordon
Gordon

Reputation: 20150

I'll answer the first question but not the second one. (Memory leaks are an important topic but I just don't know the answer; if you suspect .on('filtered',...) you might try .on('filtered', null) but I somehow doubt that's the only cycle.)

So back to how to replace data. That should be easy: just reassign the group and dimension to the chart and then call chart.render(). render always starts from scratch so it should always be safe. Even redraw often works after replacing the group and dimension, because the dc.js charts are just pulling the data from group.all() and setting filters on the dimension, so they don't much care if you replace those.

A common source of slowdown is creating more and more groups & dimensions on the same crossfilter instance, but it sounds like you are creating the crossfilter from scratch, so that's not the issue.

Upvotes: 1

Related Questions