Kartik Trivedi
Kartik Trivedi

Reputation: 51

Interactive sorting of grouped bar chart in D3js

I have generated a group bar chart based on the example provided in D3js.org example repository. Now I am trying to introduce an interactive sorting option based on another example from D3js example sets. I have three variables grouped per state. I was hoping to provide interaction where reader can sort (descending) based on - 1. Any one of the variables (but whole group should move) 3. Three different sorting options one for each variable (complicated and less important)

I am new to javascript and D3js so I am not sure of the way moving forward. Any suggestion would be greatly appreciated.

Upvotes: 4

Views: 1532

Answers (1)

muyueh
muyueh

Reputation: 1038

Without seeing your code, I can only offer a very vague direction:

you may need a function that gets called, each time the viewer change sorting option. Inside the function, you will need to specify different accessor:

var update = function(_value){
  data.sort(function(a, b) { return b._value - a._value; })

  // add transition with the newly sorted data
}

Upvotes: 1

Related Questions