誰能告訴我如何擴展Chart.js v2.0。我在折線圖中需要垂直線,我想實現類似於http://jsfiddle.net/dbyze2ga/的東西。Chart.js 2.0 - 垂直線
Chart.types.Line.extend({
name: "LineWithLine",
draw: function() {
Chart.types.Line.prototype.draw.apply(this, arguments);
var point = this.datasets[0].points[this.options.lineAtIndex]
var scale = this.scale
// draw line
this.chart.ctx.beginPath();
this.chart.ctx.moveTo(point.x, scale.startPoint + 24);
this.chart.ctx.strokeStyle = '#ff0000';
this.chart.ctx.lineTo(point.x, scale.endPoint);
this.chart.ctx.stroke();
// write TODAY
this.chart.ctx.textAlign = 'center';
this.chart.ctx.fillText("TODAY", point.x, scale.startPoint + 12);
}
});
new Chart(ctx).LineWithLine(data, {
datasetFill : false,
lineAtIndex: 2
});
如果您運行給定的鱈魚,您得到的錯誤是什麼è? – Gunaseelan
問題在於,使用Chart.js 2.0時,類層次結構發生了變化,他們現在使用每個數據集的控制器。你可以在[link]找到新的文檔(http://nnnick.github.io/Chart.js/docs-v2/#advanced-usage-extending-existing-chart-types)。我還用2.0庫創建了一個新的小提琴[鏈接](http://jsfiddle.net/1v6pjy3u/1/)。 – wannensn