سؤال

I've got a JSON of politicians, a list containing their names and party.

Very simply, what I want to do is having a bar chart, the size of the bars depending of the number of politicians from a different party.

Keys look like that:

{
    "party": "National Liberal Party – True Liberalism",
    "region": "london",
    "name": "Bernard Dube",
    "twitter": ""
  },
  {
    "party": "Alliance Party of Northern Ireland",
    "region": "northern-ireland",
    "name": "Anna Lo",
    "twitter": "Anna4Europe"
  },

Unfortunately, it is not as simple as:

{
"National Liberal Party": "330", 
"Alliance Party of Northern Ireland": "200"
}

How can I do that with d3? Thank you!

هل كانت مفيدة؟

المحلول

build the data u want:

var d = {};
records.forEach(function(i)  {
  if(d[i.party] == null) {
    d[i.party] = 0;
  }
  d[i.parts] += 1;
});
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top