1

Is it possible to get the filters applied on a particular dimension? I need to obtain all filters applied on a group of dc.js charts on click of a button.

2 Answers 2

10

I did something similar. However instead of using a button click I was getting the values each time the chart was filtered by attaching a renderlet.

The function your looking for is filters()

i.e

  yourChart.renderlet(function(chart) {
            dc.events.trigger(function() {
                console.log(yourChart.filters())
            });
        })

This will log the filters applied to the dimension given to the chart.

0

You can get the value of selected filters using the chart.filterPrinter() function which returns a function that returns a string version of the selected filters. The following code segment would return the string version of the currently selected filters for a chart.

chart.filterPrinter()(chart.filters()) 

You can even provide your own filterPrinter function for customization.

You can define on('filtered' function that is fired each time a filter value changes on a chart. This function receives the chart as the first argument, and current filter selection/un-selection as the second argument. But, you can get the full list of current selected filters using chart.filters() function.

myChart.on('filtered', function(chart, filter) {
    var sel = chart.filterPrinter()(chart.filters());
    console.log('Selected Filters are: ' + sel);
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.