Here are the basic methods you want to use:
- dc.chartRegistry.list (): retrieves an array of all the diagrams loaded by dc
- chart.filters (): retrieves an array of all filters for a given chart
- chart.filter (): applies a filter to a given chart
- dc.redrawAll (): redraws all diagrams after applying external filters.
From there, it's just a matter of serializing and deserializing objects.
Here is one way to do this by building a JSON object:
var filters = []; for (var i = 0; i < dc.chartRegistry.list().length; i++) { var chart = dc.chartRegistry.list()[i]; for (var j = 0; j < chart.filters().length; j++){ filters.push({ChartID: chart.chartID(), Filter: chart.filters()[j]}); } } var urlParam = encodeURIComponent(JSON.stringify(filters));
Here is the reverse process of parsing a JSON string and applying filters:
var urlParam = "";
The combination of the two steps will depend on your scenario. You could save the row in the database or add it as a url parameter.
Some ribs may not be present in this code, but it seems to work for basic dc.js examples.
source share