简体   繁体   English

HTML Canvas 颜色特定区域

[英]HTML Canvas color specific area

How can I do if I want to change the color of the area on the top of the drawed line.如果我想更改绘制线顶部区域的颜色,我该怎么做。 Here is my example: https://www.w3schools.com/code/tryit.asp?filename=GG3IR6IS9TZ1这是我的示例: https://www.w3schools.com/code/tryit.asp?filename=GG3IR6IS9TZ1

Thanks谢谢

Make a shape with your values and fill her.用你的价值观塑造一个形状并填充她。 https://www.w3schools.com/code/tryit.asp?filename=GG3J6QC13SU5 https://www.w3schools.com/code/tryit.asp?filename=GG3J6QC13SU5

// your graph
ctx.beginPath();
ctx.moveTo(0, 40);
ctx.lineTo(300, 60);
ctx.stroke();

// fillment
ctx.beginPath();
ctx.moveTo(0, 40); //y our dynamic values
ctx.lineTo(300, 60); // your dynamic values
ctx.lineTo(300, 300); // canvas bottom right end
ctx.lineTo(0, 300); // canvas bottom left end
ctx.closePath();

Pass this logic for a function for other graph use, keep your code dry.将此逻辑传递给 function 以供其他图形使用,保持代码干燥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM