在ng2-charts中重写chart.js .extend()功能

时间:2019-05-18 18:10:20

标签: chart.js ng2-charts

我是Chart.js和ng2-charts的新手。我想在chart.js中的.extend()功能下面以ng2-chart重写。甚至有可能吗?

这是我的小提琴:https://jsfiddle.net/haq5k2mw/

 Chart.defaults.LineWithLine = Chart.defaults.line;
 Chart.controllers.LineWithLine = Chart.controllers.line.extend({
   draw: function(ease) {
   Chart.controllers.line.prototype.draw.call(this, ease);
   if (this.chart.tooltip._active && this.chart.tooltip._active.length) {
    var activePoint = this.chart.tooltip._active[0],
       ctx = this.chart.ctx,
       x = activePoint.tooltipPosition().x,
       topY = this.chart.scales['y-axis-0'].top,
       bottomY = this.chart.scales['y-axis-0'].bottom;

    // draw line
     ctx.save();
    ctx.beginPath();
    ctx.moveTo(x, topY);
    ctx.lineTo(x, bottomY);
    ctx.lineWidth = 2;
    ctx.strokeStyle = '#07C';
    ctx.stroke();
    ctx.restore();
   }
  }
});

0 个答案:

没有答案