ChartJS Doughnut Charts Gradient Fill(ChartJS 甜甜圈图表渐变填充)
问题描述
所以我尝试为 ChartJS 圆环图制作渐变填充,但这仅适用于水平而不是圆形.
So I tried to make a gradient fill for the ChartJS doughnut chart, but this only works horizontal and not in a circle.
这是我正在使用的代码:
This is the code that I'm using:
是否可以在半径上实现渐变,如本设计所示?
Is it possible to implement the gradient on a radius, as seen on this design?
谢谢!
推荐答案
在像圆环图这样的非线性路径上绘制线性渐变时,ChartJS 不会(正确)使用渐变填充颜色.线性渐变不会弯曲.
ChartJS will not (properly) use gradient fill colors when drawing a linear gradient on non-linear paths like your donut chart. A linear gradient does not curve.
可能性#1——使用径向渐变
您可以尝试使用径向渐变,看看结果是否符合您的设计需求.
You might experiment with a radial gradient and see if the results meets your design needs.
可能性 #2——使用渐变笔触(DIY 项目)
此外,画布的笔触会围绕一个圆圈弯曲.
Also, canvas's stroke will curve around a circle.
如果你想自己滚动"渐变圆环图,这里有示例代码和一个在圆形路径上使用渐变 strokeStyle 的演示(请参阅我之前的答案:画布中的角度渐变):
If you want to "roll-your-own" gradient donut chart, here's example code and a Demo that uses a gradient strokeStyle on a circular path (see my previous answer here: Angle gradient in canvas):
这篇关于ChartJS 甜甜圈图表渐变填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!