我正在使用 D3(技术上是 C3)来尝试创建分组条形图。
我正在尝试制作的图表将是每个职业的捐赠条形图,按 PaymentType 分组。对于我的生活,我无法弄清楚如何进行分组。
这是我到目前为止的代码。它产生我想要的一切,除了按 PaymentType 分组:
var x_values = ["Occupation", "DENTIST", "PROGRAMMER/ANALYST", "CORPORATE SECRETARY", "PHYSICIAN", "PROFESSOR", "PRESIDENT", "PROFESSOR", "MANAGER", "CORPORATE SECRETARY", "PRESIDENT", "PHYSICIAN", "DENTIST", "PROGRAMMER/ANALYST", "CO-OWNER", "MANAGER", "CO-OWNER"]
var y_values = ["Donation", 11340, 12335, 3259, 18041, 10415, 35900, 14660, 21985, 2950, 15110, 16705, 370, 22255, 13055, 4000, 20740]
var z_values = ["PaymentType", "MONETARY", "NON-MONETARY", "NON-MONETARY", "MONETARY", "MONETARY", "NON-MONETARY", "NON-MONETARY", "MONETARY", "MONETARY", "MONETARY", "NON-MONETARY", "NON-MONETARY", "MONETARY", "MONETARY", "NON-MONETARY", "NON-MONETARY"]
var chart = c3.generate({
data: {columns: [y_values],
type: 'bar',
groups: [z_values],},
axis: {x:
{type: 'category',
categories: x_values}}
});