score:1

Accepted answer

I find it is useful to give people the example instead of making them run it themselves. See here: http://tributary.io/inlet/5835233.

Around line 157 where it says

d.population.forEach (function(d){
  color.domain(d3.keys(d).filter(function(name) {
  return name;
}

name is always either "category" or "strength". This is because of how your data is arranged. I think what you want is to have your data be

{year: 2008, 
population: {
    category1: 20,
    category2: 43,
    category3: 55}
}

If you put your data like this, you'll have to mess around with how exactly you are setting the domain of your color instance, since forEach only works on arrays, and we have now set the data to be in an object. Something like color.domain(d3.keys(d.population)). Fork my example on tributary and try a couple things. Look at the d3.keys() documentation to see how it works.


Related Query

More Query from same tag