I am trying to assign different colors to each bar in a columnchart, but when I try every bar gets the same color.
Code:
// Load the Visualization
Change to:
...
// Create the data table.
var data = new google.visualization.DataTable();
var raw_data = [
['A', 40],
['B', 17],
['C', 7]
];
data.addColumn('string', 'Columns');
for (var i = 0; i < raw_data.length; ++i) {
data.addColumn('number', raw_data[i][0]);
}
data.addRows(1);
data.setValue(0, 0, 'row');
for (var i = 0; i < raw_data.length; ++i) {
data.setValue(0, i+1, raw_data[i][1]);
}
// Set chart options
...
=== UPDATE ===
A simplified version:
...
// Create the data table.
var data = new google.visualization.DataTable();
var raw_data = {
'A': 40
, 'B': 17
, 'C': 7
};
data.addRows(1);
var i = 0;
for (var index in raw_data) {
data.addColumn('number', index);
data.setValue(0, i++, raw_data[index]);
}
// Set chart options
...