Reputation: 1277
How to define specified color for the Label name in Google Pie Chart? For example, "Label1" must be red always. "Label2" green. Labels generated by server and it is possible that there will be other labels, but that two must be red and green. The rest should different color.
There is 'label' option in Google Charts, but I don't see any label name in that.
Thanks,
Upvotes: 1
Views: 2827
Reputation: 103
I think we had the same problem. In my case I had to combine ledger account numbers with certain colors in my Google pie charts. So while constructing my array data for the pie-chart I also create an array colors. In that loop I use this:
var list = [];
$.each(dataObj.model_Response[0].array, function(key, item) {
var row = [];
var value = item.account.amount;
colors.push(_toColor(item.account.number.toString()));
row.push(item.account.name);
row.push(value);
list.push(row);
});
//.. list add to google DataTable.
The _toColor function:
var _toColor = function(n) {
n = crc32(n);
n &= 0xffffffff;
return("#" + ("000000" + dechex(n)).substr(-6));
}
In my options var I can simply assign the array:
colors: result['colors'],
And the result is two pie-charts with linked ledger account and colors! Hopefully I have been clear enough, if you still have questions about this let me know.
This is the result of my two pie-charts:
Upvotes: 2