![](/img/trans.png)
[英]Apply 2D canvas (image + text) to 3D surface and do 360 degree rotation/animation - possible to do this with HTML5/CSS3/Javascript or Flash necessary?
[英]Is it possible to apply css to text in a canvas tag
我有一个canvas标记,里面带有文本(由jqplot图表渲染):
<canvas id="myCanvas" width="578" height="200"></canvas>
有什么办法可以使画布内的文本变为红色? 我已经尝试过像这样添加CSS:
<canvas id="myCanvas" width="578" height="200" style="color: red;"></canvas>
据我了解,画布几乎就像一幅图像。 这是否意味着我将无法在该画布中选择内容?
由于您正在使用jqplot
,因此应查看文档以了解如何更改文本的颜色。 以下网页看起来很有希望,其中提到了textColor
属性。
http://www.jqplot.com/docs/files/plugins/jqplot-canvasAxisLabelRenderer-js.html# $ .jqplot.CanvasAxisLabelRenderer
这看起来也很有帮助
http://www.jqplot.com/docs/files/jqplot-core-js.html#Axis.tickRenderer
http://www.jqplot.com/docs/files/jqplot-axisTickRenderer-js.html# $ .jqplot.AxisTickRenderer
基本上,我将尝试查找在绘制每个刻度之前被调用的事件(挂钩)。 找出要绘制的刻度线。 然后根据该信息更改文本颜色。 我相信您可以通过我为您提供的服务来实现。
您可以使用Javascript完成:
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
context.font = '40pt Calibri';
context.fillStyle = 'blue';
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.