使用 Canvas 绘制图表
我使用 HTML 画布制作一些图表,但我想用多种颜色绘制线条,在每一点上它都应该更改为新的随机颜色,
ctx.moveTo(Ximg+46,Yimg+200);
for(i=0;i<num;i++){
if(js_array[i]=="900"){ctx.strokeStyle = "Grey";}
else{ctx.lineTo(Ximg+50+i*mul,(Yimg+200)-(js_array[i]*(height/max)));}
}
我将把灰色更改为随机,但问题是它用灰色将先前的路径(线)着色,我想要每条线有不同的颜色,在 Javascript 中可以吗?
在 OpenGl 中,我们曾经编写过一个命令来始终获取最后给定的颜色或不获取,Javascript 中是否有类似的命令?
I making some graphs using HTML canvas but I want to draw line with multiple colors, at every point it should change to a new random color,
ctx.moveTo(Ximg+46,Yimg+200);
for(i=0;i<num;i++){
if(js_array[i]=="900"){ctx.strokeStyle = "Grey";}
else{ctx.lineTo(Ximg+50+i*mul,(Yimg+200)-(js_array[i]*(height/max)));}
}
am gonna change grey to random but the problem is it colors the previous path(line) with grey,i want each piece of line in a different color,is it possible in Javascript?
in OpenGl there was command we used to write to take always the last given color or not,is there a similar one in Javascript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在上下文中,StrokeStyle 属性可以采用 rgba、rgb 和十六进制颜色以及颜色名称。
我会建议一些类似的东西:
或者也许是一个返回颜色或分配颜色的新函数。
如果这不是您想要的,您能否为未声明的变量提供一些值,以便我们可以更彻底地测试它?
With the context, the strokeStyle property can take rgba, rgb, and Hexadecimal colors as well as the name of the color.
I would suggest something along the lines of:
Or perhaps a new function that returns the color, or assigns it.
If that wasn't what you were looking for, could you supply some values for the undeclared variables so that we can test it more thoroughly?