我正在通过绘制一条水平线来自定义图表,并且正在使用插件
我声明了我的插件
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);
实际上我收到此错误
键入'{''horizontalLine':{'y':any; 'style':字符串; '文本':字符串; } []; showLines:true;图例:{...'不能分配给'ChartOptions'类型。
对象文字只能指定已知的属性,而“ ChartOptions”类型中不存在“ horizontalLine”。
但是应用程序正在运行,并且我可以根据需要获得一条水平线。