我需要按国家/地区来绘制各自类别的图表。
{ID = 1, Name = "n1", Country="Egypt",Budget=100,
Goal="Free",Category="Sports"},{ID = 2, Name = "n2",
Country="Egypt",Budget=120, Goal="Free",Category="Space"},{ID = 3, Name =
"n3", Country="Algeria",Budget=50, Goal="Free",Category="Media"},{ID = 4,
Name = "n4", Country="Libya",Budget=50, Goal="Free",Category="Media"}
var categorynobyCountry = d3.nest()
.key(function (d) { return d.Country; })
.key(function (d) { return d.Category; })
.rollup(function(v) { return v.length; })
.entries(j);
var data = [];
for (var o = 0; o < categorynobyCountry.length; o++) {
for (var i = 0; i < categorynobyCountry[o].values.length; i++) {
data.push({
label: categorynobyCountry[o].values[i].key,
y: categorynobyCountry[o].values[i].value
});
}
}
window.onload = function () {
var chart = new CanvasJS.Chart("container", {
title:{
text: "Chart"
},
data: [{
type: "column",
dataPoints:data
},
{
type: "column",
//dataPoints: dataPoints
}]
});
chart.render();
}
每个国家/地区应根据类别的数量来划分多列,而y轴是每个国家/地区的类别总和