如何访问 AnyChartJS 函数中传递的数据?
How to access data passed within a function in AnyChartJS?
我正在尝试将我的甘特图任务栏更改为圆角。
学习本教程 here。但是这个示例没有对进度条进行修改,所以我使用方法progress()
访问进度条并添加了这个:
tasks.progress().rendering().drawer(drawingFunction)
我注意到如果我将圆角应用到 zero progressValue
的数据,它会显示 concave[=46] 的进度条=] 角落,进度不应该完全可见或至少凸角 (可能的错误):
现在作为解决方法,我正在考虑为 progressValue = 0
添加验证并将其从那里移动,但接下来的问题是如何在 [=16= 中获取 progressValue
的值]?
// 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')
有关详细信息,请查看 modified sample。
绘图功能没有错误。您会得到带有凹角的钢筋,因为钢筋宽度小于角半径的 2 倍。当进度值很小时,您必须减小半径或以某种方式处理这种情况。
我正在尝试将我的甘特图任务栏更改为圆角。
学习本教程 here。但是这个示例没有对进度条进行修改,所以我使用方法progress()
访问进度条并添加了这个:
tasks.progress().rendering().drawer(drawingFunction)
我注意到如果我将圆角应用到 zero progressValue
的数据,它会显示 concave[=46] 的进度条=] 角落,进度不应该完全可见或至少凸角 (可能的错误):
现在作为解决方法,我正在考虑为 progressValue = 0
添加验证并将其从那里移动,但接下来的问题是如何在 [=16= 中获取 progressValue
的值]?
// 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')
有关详细信息,请查看 modified sample。
绘图功能没有错误。您会得到带有凹角的钢筋,因为钢筋宽度小于角半径的 2 倍。当进度值很小时,您必须减小半径或以某种方式处理这种情况。