Skip to content

Chart where line above/below a certain value has a different color #11727

Answered by stockiNail
Baspa asked this question in Q&A
Discussion options

You must be logged in to vote

@Baspa AFAIK you should use the canvas gradients to reach the goal. Even if the background color can be managed by fill option (https://www.chartjs.org/docs/latest/charts/area.html#filling-modes) and have different fill color with a baseline, this is not possible for border color (color of the line).
The color of the line cannot be changed between the 2 points used to draw the line, even if you use the segment option (https://www.chartjs.org/docs/latest/charts/line.html#segment).

That said, the gradient sounds the right direction. You can managed them by yourself of you can use a specific Chart.js plugin, chartjs-plugin-gradient.

Here an example, close to your use case: https://codepen.io…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Baspa
Comment options

Answer selected by Baspa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants