我已经使用了 chart.js 1.0.2,但不知道版本 2+ 已经到来。现在我需要仅在 2+ 中可用的功能同时我已经为 chart.js 1.0.2 编写了几个扩展,我想将其转换为 2+ 版本。
Chart.types.Doughnut.extend(
{
name: "DoughnutWithText",
draw: function() {
Chart.types.Doughnut.prototype.draw.apply(this, arguments);
width = this.chart.width,
height = this.chart.height;
var fontSize = (height / this.options.textScale).toFixed(2);
this.chart.ctx.font = fontSize + "em Lato";
this.chart.ctx.textBaseline = "middle";
this.chart.ctx.fillStyle="#000";
textX = Math.round((width - this.chart.ctx.measureText(this.options.doughnutText).width) / 2),
textY = height / 2;
this.chart.ctx.fillText(this.options.doughnutText, textX, textY);
}
});
如何在版本 2+ 中执行此操作?