dc.js icon indicating copy to clipboard operation
dc.js copied to clipboard

Changing dimensions on runtime

Open pdaems opened this issue 13 years ago • 1 comments

Im trying to change the dimension and group of my barChart depending on the date range that you select just like in the nasdaq example.

                               .on("filtered", function (chart) {
                               dc.events.trigger(function () {
                                    var extent = volumeChart.brush().extent();
                                    var diff = daydiff(new Date(extent[0]), 
                                     new Date(extent[1]));
                                    // //alert(diff);
                                    if (diff > 0 && diff <=10) {
                                        barChart.dimension(datedimensionByHour);
                                        barChart.group(barGroupByHour);
                                    } else {
                                        barChart.dimension(datedimension);
                                        barChart.group(barGroup);
                                    }
                                   barChart.focus(chart.filter());
                               });

It properly changes the datedimension to hour whenever the difference between the two dates is between 10. Whenever the difference is greater then 10 it triggers the else function but the dimension and group don't seem to be applied to the barChart. Seems like the chart can only handle 1 switch.

Is this normal behaviour ? Also i use datedimension and barGroup as my starting dimension and group when I declare the chart.

pdaems avatar Sep 18 '13 07:09 pdaems

@pdaems It should work, but it isn't really a use case that has been tested. Offhand you might want for force a full render, rather than just a redraw. If you can provide a functional example somewhere, I can take a look. It might be a bug or something we can otherwise address. Also try upgrading the the latest d3, I know they just fixed some bugs in 3.3.6 that might be related when changing scales.

jrideout avatar Sep 28 '13 00:09 jrideout