首页 > 解决方案 > 如何访问 AnyChartJS 中函数内传递的数据?

问题描述

我正在尝试将甘特图任务栏更改为圆角。

在此处遵循本教程。但是这个示例没有对进度条进行修改,所以我使用了progress()访问进度条的方法并添加了这个:

tasks.progress().rendering().drawer(drawingFunction)

我注意到,如果我将圆角应用于 progressValue的数据,它会显示带有角的进度条,这些进度根本不应该可见,或者至少是凸角不可见(可能的错误)

在此处输入图像描述

现在作为解决方法,我正在考虑添加验证progressValue = 0并将其从那里移动,但接下来的问题是如何获得progressValueinside的值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(); 

}

我尝试了什么:

是否有任何类似的全局方法可以在任何地方访问数据?

标签: javascriptanychartanychart-8.2

解决方案


drawingFunction()您可以像这样获得所需的值:

this.tag.item.get('progressValue')

有关详细信息,请查看修改后的示例

绘图功能没有错误。您会得到带有凹角的钢筋,因为钢筋宽度小于 2 倍拐角半径。当进度值非常小时,您必须减小半径或以某种方式处理这种情况。


推荐阅读