I am creating a basic dashboard of charts, using chart.js to render the data. I have a javasciprt per chart that gets the data and draws each chart to the dashboard (so that I can create multiple dashboards, and re use certain charts wherever.) I want to be able to store a list of colours in css, so that charts can use the same colours to represent the same item, even when in a different style of chart.
Ive looked into using :root in css and using the get property value to retrieve the variable, but this doesn't seem to work. Am I going about this the right way?
CSS:
:root {
--mediumRiskColour: blue;
}
Javascript to get the variable:
var mediumRiskColour = getComputedStyle(document.documentElement).getPropertyValue('--mediumRiskColour');
// Javascript to then use this variable in the chart:
{
label: 'Medium risk
data: mediumRisk,
borderColor: 'mediumRiskColour',
backgroundColor: 'mediumRiskColour',
},
I would like the colour to be pulled from the css so that I can use it to colour items in a chart that is rendered in javascript