I'm setting up a simple web chart using chart.js. Given a hexadecimal color value like C8C8C8
, I want to get rgba(200, 200, 200, x)
. The x
is passed as a second variable. My code looks like this:
function colorconvert(color, transparency) {
var r = parseInt(color.substring(0,2),16);
var g = parseInt(color.substring(2,4),16);
var b = parseInt(color.substring(4,6),16);
var a = parseInt(transparency);
return ('rgba(r, g, b, a)');
}
But Chrome dev console logs the error:
Uncaught Error: Unable to parse color from string "rgba(r, g, b, a)"
What am I doing wrong? Any help is appreciated!