[Chartjs]-Is it possible to avoid the shrinking of Chart.js pie charts when accompanied by labels?

3👍

Yes, this is fairly simple actually. The chartjs-plugin-labels.js file contains several lines which force the chart to become smaller when the label settings set the position to either "border" or "outside". Download the script to your own server, comment out the lines below, and everything should work as expected. CodePen demo

Comment/remove these lines:

if (this.options.position === 'border') {
  offset = (lines.length - 1) * this.options.fontSize / 2;
}
if (label.options.position === 'outside') {
  someOutside = true;
  var padding = label.options.fontSize * 1.5 + label.options.outsidePadding;
  if (padding > maxPadding) {
    maxPadding = padding;
  }
}

Here is the updated JS file you can use: https://pastebin.com/raw/gSffqqKu

Just download it as chartjs-plugin-labels.js and use it in your project instead of the original plugin file.

Leave a comment