Abdelmoghite Kacimi
Abdelmoghite Kacimi

Reputation: 183

Get the key of selected data in DC js

I want to know if it's possible to get key or id of selected data in DC js. I have a pie chart representing town, and I want to retrieve the id every time my chart is filtered
Here is the structure of my data:

{
    "id":101,
    "sup":20.57,
    "town":"Abercorn",
    "soilType":"Argile limoneuse",
    "renting":"Non",
    "rentCost":0.0,
    "drain":"Oui",
    "lastASOL":2015

}

Upvotes: 1

Views: 722

Answers (1)

Krishna Vedula
Krishna Vedula

Reputation: 1791

Also, the chart.filterPrinter() function 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()) 

As mentioned by Gordon above, you can define 'filtered' function that receives the chart as the first argument, and current filter selection/unselection as the second argument

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

Upvotes: 1

Related Questions