Chart.js - Increase spacing between legend and chart

Bryan Lewis picture Bryan Lewis · Mar 3, 2017 · Viewed 29.9k times · Source

I have a bar chart where I have drawn 3 vertical lines, each with it's own label at the top. I would like those labels to be above the top of the y-axis (above the 30% line in the example) but below the legend. I can't figure out how to increase the space between the top legend and the chart such that I can have my vertical line labels (15, 24 & 33) be off of the chart itself but below the legend. Any ideas?

Example Chart

Answer

Dorian Maliszewski picture Dorian Maliszewski · Sep 28, 2018

If you want do increase spacing in all charts you can put this code before creating :

Chart.Legend.prototype.afterFit = function() {
    this.height = this.height + 50;
};

Of course, I don't try but i think you can change it (or copy the original Chart object before, to keep the original padding).

Bye,