If I understand correctly, you want to color the bars on the chart based on some calculation (variant)? Is that variant constantly changing and you want the chart to update as it changes?
I'm not sure if options.elements.bars
would be the correct place to do it. As I understand it, those properties are there to globally define styles for the listed elements.
Although, it does seem to work...
The arrow function would get called every time the chart is drawn/updated. The ctx
object will contain the x and y values for a single bar. In other words, for every bar that must be drawn, the arrow function on backgroundColor
would be called with a new ctx
object for the respective bar.
Post a sample of your dataset for us to see, if you can.
Be sure to follow this guide when posting code/data.
Wiki - how to post code on this forum - General Discussion - Inductive Automation Forum
The "traditional" way would be to add the backgroundColor
property to your dataset.
See this link for more info: Vertical Bar Chart | Chart.js