小编wan*_*nsn的帖子

Chart.js 2.0 - 垂直线

任何人都可以告诉我如何扩展Chart.js v2.0.我需要在折线图中使用垂直线,我想实现类似于http://jsfiddle.net/dbyze2ga/的内容.

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
 });
Run Code Online (Sandbox Code Playgroud)

chart.js

13
推荐指数
2
解决办法
2万
查看次数

标签 统计

chart.js ×1