Created
September 5, 2014 11:30
-
-
Save joews/53a3621dcc47f8822611 to your computer and use it in GitHub Desktop.
c3.js categorical bar chart with colour per category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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