I have been using nvd3 for a long time. In nvd3 we have an option to specify automatic graph fill colors.
chart.barColor()
How can I fill random colors in Chart.js graphs without defining each color in datasets?
I don't want to use JavaScript function to generate and get random colors from it. I need something similar to nvd3 barColor()
If there is a possible way, then please help me out.
function getRandomColor() {
var letters = '0123456789ABCDEF'.split('');
var color = '#';
for (var i = 0; i < 6; i++ ) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
Then set:
fillcolor = getRandomColor()
I am afraid there just is no in-built function in chart.js library for doing this. And what is the harm in defining your own javascript function anyways?
The implementation would look pretty much similar to what you are looking for, except that you would have defined what barColor()
would do yourself.
If you haven't found them already, there are a couple of great solutions here. (using JavaScript functions)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With