Reputation: 76
I'm trying to build a visualisation to graph what I've been reading this year.
Currently I have everything grouped via Quantity of novels. I'm wondering if it's possible to change the group in real time or if I'm stuck with a group once I've set it.
The code that I've got now to calculate the groups looks something like this:
function groupByType(dimension){
if($('#ValueType').is(':checked')) {
console.log("Pages")
return dimension.group()
.reduceSum(function(d) {
return d.Pages;
});
} else {
console.log("Volumes");
return dimension.group();
}
}
Whenever the checkbox (#ValueType) is clicked I'm calling a dc.redraw on the entire graph which I was hoping would change the way the group is being calculated but it's not doing so. Is there way to change the group dynamically or would I be better off just refreshing the page and passing a parameter when it loads?
Upvotes: 0
Views: 553
Reputation: 6010
It's a bit hard to tell, but it looks like every time you check or uncheck the checkbox, you create a new group. You do not want to do this as the groups stick around and continue getting updated. Things will just get slower and slower.
Just create the 2 groups upfront (and perhaps even 2 dc.js charts) and then let the checkbox control which group is assigned to the chart or which chart is displayed.
Upvotes: 1