Chartjs选项无法识别的类型

时间:2019-02-27 14:35:17

标签: javascript angular typescript charts chartjs-2.6.0

我正在通过绘制一条水平线来自定义图表,并且正在使用插件

我声明了我的插件

soap_dom_node

然后我在全球范围内注册

var horizonalLinePlugin = {
  afterDraw: function(chartInstance) {
    var yScale = chartInstance.scales["y-axis-0"];
    var canvas = chartInstance.chart;
    var ctx = canvas.ctx;
    var index;
    var line;
    var style;
    var yValue;

    if (chartInstance.options.horizontalLine) {
      for (index = 0; index < chartInstance.options.horizontalLine.length; index++) {
        line = chartInstance.options.horizontalLine[index];

        if (!line.style) {
          style = "rgba(169,169,169, .6)";
        } else {
          style = line.style;
        }

        if (line.y) {
          yValue = yScale.getPixelForValue(line.y);
        } else {
          yValue = 0;
        }

        ctx.lineWidth = 3;

        if (yValue) {
          ctx.beginPath();
          ctx.moveTo(0, yValue);
          ctx.lineTo(canvas.width, yValue);
          ctx.strokeStyle = style;
          ctx.stroke();
        }

        if (line.text) {
          ctx.fillStyle = style;
          ctx.fillText(line.text, 0, yValue + ctx.lineWidth);
        }
      }
      return;
    }
  }
};

然后我像这样使用它

Chart.pluginService.register(horizonalLinePlugin);

实际上我收到此错误

  

键入'{''horizo​​ntalLine':{'y':any; 'style':字符串; '文本':字符串; } []; showLines:true;图例:{...'不能分配给'ChartOptions'类型。

     

对象文字只能指定已知的属性,而“ ChartOptions”类型中不存在“ horizo​​ntalLine”。

但是应用程序正在运行,并且我可以根据需要获得一条水平线。

0 个答案:

没有答案
相关问题