Skip to content

Instantly share code, notes, and snippets.

@joews
Created September 5, 2014 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joews/53a3621dcc47f8822611 to your computer and use it in GitHub Desktop.
Save joews/53a3621dcc47f8822611 to your computer and use it in GitHub Desktop.
c3.js categorical bar chart with colour per category
var colorScale = d3.scale.category10();
var chart = c3.generate({
bindto: '#bar-chart',
data: {
x: 'x',
columns: [
['x', 'apple', 'banana'],
['count', 191, 238],
],
groups: [
['count']
],
type: 'bar',
// probably not dependable across c3 version changes - undocumented
// color is called many times, some of which correspond to
// category bars. Use presence of index to check.
color: function(inColor, data) {
if(data.index !== undefined) {
return colorScale(data.index);
}
return inColor;
},
},
axis: {
x: {
type: 'category'
}
},
size: {
width: 400,
height: 400
},
tooltip: {
show: false
},
legend: {
show: false
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment