javascript - Javascript画布,颜色未正确应用
问题描述
我有以下 javascript 画布在屏幕上绘制一堆文本
//Draws the prices fonts
priceList.map((i, index) => {
ctx.font = "11px Ariel"
if(index == 0){
ctx.fillText(i.toFixed(2), ctx.canvas.width - 42, (heightPoints * index) + 9); //This one is being painted in black
}else{
ctx.fillText(i.toFixed(2), ctx.canvas.width - 42, (heightPoints * index) - 5);
}
ctx.fillStyle = "lightblue";
})
生成的画布是以下数字
如您所见,有一个圆圈,那是因为那个数字的字体是黑色的,我似乎无法改变它的颜色
当 index === 0 时绘制
为什么会这样?为什么不为每个元素应用fillStyle?
编辑:显然它被画了,但我不能把它弄下来
更新:显然,即使它被记录,最后一个值,我也无法在任何地方绘制它我试图在任意(屏幕中心)位置绘制它并且它不会显示
priceList.map((i: number, index: number) => {
ctx.font = "11px Arial"
if(index === 0){ //nowhere to be found
ctx.fillText("aaaaaaaaaaaaaaaaaaa", 500, 500);
console.log(i) //64854.00000000001
console.log(ctx.canvas.height) //885
console.log(ctx.canvas.width) //1157
}else{
ctx.fillText(i.toFixed(2), ctx.canvas.width - 46, (heightPoints * index) - 5);
}
ctx.fillStyle = "orange";
})
解决方案
推荐阅读
- laravel - 将 laravel 7 更新到 8.47 后找不到类 '\App\User'
- java - 在 Hibernate 从 5 迁移到 5.5 后,将实体添加到集合会导致 ConstraintViolationException
- python - 具有张量流概率的真实 NVP
- php - 在 CakePHP 4.x 中禁用会话超时
- android - 如何在不丢失图像质量的情况下完美地将图像放入 imageview android
- python - 从橙色动态检测红色的阈值方法
- c - 您可以使用 struct XrmOptionDescRec 数组将非 Motif 相关参数传递给应用程序吗?
- reactjs - 如何在反应中使用上下文 api 将数据添加到其余 api?
- .net - 什么是捕获取消订阅事件的最佳方式
- c - 为什么我的 MingW-64 位编译的 64 位 Windows .EXE 在添加简单的字符串分配时会崩溃,而对于 32 位它可以正常工作?