I am using D3 (technically C3) to try to create a grouped bar chart.
The chart I am trying to make would be a bar chart of Donations per occupation, grouped by PaymentType. For the life of me I can't figure out how to do the grouping.
This is a code I have so far. It produces everything I want, except the grouping by 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}}
});
Something like this?
Fiddle - http://jsfiddle.net/63cp42Lv/
If you want to make the bars appear side by side instead of stacked, just remove the groups property.