Chart.js: Giving Gradient fill color based on the value.

Created on 11 May 2020  ·  4Comments  ·  Source: chartjs/Chart.js

Documentation Is:

  • [x] Missing or needed
  • [ ] Confusing
  • [ ] Not Sure?

Please Explain in Detail...

I need to give 3 different colors as gradient color in the background in the "line chart". These colors should be based on the values.

value and colors

120 to 200: green color
60 yo 120 : blue color
0 to 60: Orange color.
also when no value with data above 120 is given as parameter green color should not be displayed.
I have attached the image.

Thanks,
chart

documentation

Most helpful comment

I created a plugin to ease the pain: https://github.com/kurkle/chartjs-plugin-gradient :)

All 4 comments

@vinayaknk Here is the latest doc about canvas gradients/patterns usage.
Here is the doc to CanvasGradient.

I think the complex part is to create a gradient with the right dimension of chart in order to apply the change color to the right threshold.

I created a plugin to ease the pain: https://github.com/kurkle/chartjs-plugin-gradient :)

I think with the plugin, we can call this working.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bytesnz picture bytesnz  ·  3Comments

SylarRuby picture SylarRuby  ·  3Comments

JewelsJLF picture JewelsJLF  ·  3Comments

benmccann picture benmccann  ·  3Comments

longboy picture longboy  ·  3Comments