[Chartjs]-Angular Chart JS prevent x label causing overflow

0๐Ÿ‘

โœ…

See this example: https://jsfiddle.net/9r6nt0tu/

You could add right-padding of 10px to the chart and expand callback function hide the last label by returning an empty string.

callback: (value,index,values) => {
  // don't show last tick label
  if (index+1 >= values.length) {
    return '';
  }

  ...
}

As K Scandrett recommends, label rotation could also be used if many chart values exist.

-1๐Ÿ‘

You can eliminate that extra whitespace by forcing rotation:

xAxes: [{
   ticks: {
      autoSkip: false,
      maxRotation: 45,
      minRotation: 45
   }
}]

Here is a demo with a before and after http://jsbin.com/dorapekizo/edit?html,js,output

Original idea came from https://stackoverflow.com/a/39706742/1544886

Leave a comment