score:1

Accepted answer

you can do this by hooking into the draw function of the first point (because you are basically closing off the path drawn by the line to do the fill) and using the y = 0 points to close off the path, like so.

chart.types.line.extend({
    name: "linealt",
    initialize: function (data) {
        chart.types.line.prototype.initialize.apply(this, arguments);

        var scale = this.scale;
        var firstdataset = this.datasets[0];
        var firstpoint = firstdataset.points[0];
        var min = (scale.min > 0 ? scale.min : (scale.max > 0 ? 0 : scale.max));

        originaldraw = firstpoint.draw;
        firstpoint.draw = function () {
            ctx.lineto(firstdataset.points[firstdataset.points.length - 1].x, scale.calculatey(min));
            ctx.lineto(firstdataset.points[0].x, scale.calculatey(min));
            ctx.fillstyle = firstdataset.fillcolor;
            ctx.closepath();
            ctx.fill();

            return originaldraw.apply(this, arguments);
        }
    }
});

and you also have to turn off the datasetfill option (since we are doing it on our own)

var mychart = new chart(ctx).linealt(data, {
    datasetfill: false
});

if you also want to move the x axis labels, the cleanest way to do it would be to turn off the current labels and just draw your own using the xlabels collection


fiddle - http://jsfiddle.net/dnpo61tu/


Related Query

More Query from same tag