简体   繁体   English

在画布上分层

[英]Layering on canvas

I currently working on prototype which display some data as vague-meter: back-ground gray arc show start to end limit, the blue arc show the current value. 我目前正在研究原型,该模型将一些数据显示为模糊表:背景灰色弧形显示开始到结束极限,蓝色弧形显示当前值。 I adding line-stroke at start and end of back-ground gray arc. 我在背景灰色弧的起点和终点添加了笔触。

在此处输入图片说明

For drawing this I am using html canvas. 为了进行绘制,我使用html canvas。

var ctx ;

var currVague=document.getElementById("currVague");

ctx = currVague.getContext("2d");
ctx.beginPath();
ctx.arc(122,122,99,0.81*Math.PI,0.19*Math.PI);
ctx.strokeStyle="#555";
ctx.lineWidth=16;
ctx.stroke();

ctx.beginPath();
ctx.arc(122,122,99,0.81*Math.PI,0.12*Math.PI);
ctx.strokeStyle="#3872C1";
ctx.lineWidth=16;
ctx.stroke();

ctx.strokeStyle="#949494";
ctx.moveTo(25,175);
ctx.lineTo(50,175);
ctx.lineWidth=5;
ctx.stroke();

This first time I am trying canvas, and not sure why the gray curve showing in foreground. 这是我第一次尝试使用画布,但不确定为什么灰色曲线显示在前景中。

Just add a beginPath() in the last section where you draw the line: 只需在画线的最后一部分中添加一个beginPath()

ctx.strokeStyle="#949494";
ctx.beginPath();     /// here needs to be a beginPath()
ctx.moveTo(25,175);
ctx.lineTo(50,175);
ctx.lineWidth=5;
ctx.stroke();

If you don't what happens is that the previous arc is still a part of the path and when you stroke it that arc and your newly added line will both be stroked. 如果不这样做,则上一条弧线仍是路径的一部分,并且当您对其进行笔划时,该弧线和新添加的线都将被描画。 To "break" the path so-to-speak just call beginPath() and only what is added afterwards will be stroked (or filled) next time. 要“打破”要说的路径,只需调用beginPath() ,下次将仅beginPath() (或填充)之后添加的内容。

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

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