javascript - 如何访问 AnyChartJS 中函数内传递的数据?
问题描述
我正在尝试将甘特图任务栏更改为圆角。
在此处遵循本教程。但是这个示例没有对进度条进行修改,所以我使用了progress()
访问进度条的方法并添加了这个:
tasks.progress().rendering().drawer(drawingFunction)
我注意到,如果我将圆角应用于零 progressValue
的数据,它会显示带有凹角的进度条,这些进度根本不应该可见,或者至少是凸角不可见(可能的错误):
现在作为解决方法,我正在考虑添加验证progressValue = 0
并将其从那里移动,但接下来的问题是如何获得progressValue
inside的值drawingFunction()
?
// a function for drawing custom elements
var drawingFunction = function () {
// get the shapes of the element
var shapes = this["shapes"];
// get the shape to be modified
var path = shapes["path"];
// get the bounds of the element
var bounds = this["predictedBounds"];
var h = bounds.height;
var t = bounds.top;
var l = bounds.left;
var r = bounds.left + bounds.width;
var h1 = bounds.top + bounds.height;
var h4 = h / 4;
var h2 = h / 2;
// draw a rounded rectangle
path.moveTo(l + h4, h1 - h4)
path.arcTo(h4, h4, -270, 180)
path.lineTo(r - h4, t + h4)
path.arcTo(h4, h4, -90, 180)
path.lineTo(l + h2, h1 - h4)
path.close();
}
我尝试了什么:
- 在 中传递一个参数
drawingFunction
并使用它访问它:myparameter.item.na.progressValue
。这行得通,但它有点肮脏。 - 试过了
this.value
,,,this.getValue('progressValue')
。this.getValue('value')
但一无所获。
是否有任何类似的全局方法可以在任何地方访问数据?
解决方案
在drawingFunction()
您可以像这样获得所需的值:
this.tag.item.get('progressValue')
有关详细信息,请查看修改后的示例。
绘图功能没有错误。您会得到带有凹角的钢筋,因为钢筋宽度小于 2 倍拐角半径。当进度值非常小时,您必须减小半径或以某种方式处理这种情况。
推荐阅读
- ios - 视图约束不更新
- date - 谷歌表格“ctrl+;” 进入明天的日期?
- docker - 如何从 devcontainer 转发 UDP 端口?
- python - 编码自定义似然 Pymc3
- google-sheets - 使用双引号在 Google 表格中导出 CSV 输出 3 个双引号
- python - 我们如何在 sqlmodel 中迁移数据库?
- javascript - 强制 mocha 要求返回值?
- javascript - Javascript动态替换正则表达式匹配
- linux - 在 Debian 11 (Bullseye) 上,docker 容器内的 /proc/self/cgroup 不显示 docker 信息
- amazon-web-services - 如何从其 ARN 中获取 AWS 角色的友好名称?