Padding

Padding values in Chart options can be supplied in couple of different formats.

Number

If this value is a number, it is applied to all sides (left, top, right, bottom).

For example, defining a 20px padding to all sides of chart:

  1. let chart = new Chart(ctx, {
  2. type: 'line',
  3. data: data,
  4. options: {
  5. layout:
  6. padding: 20
  7. }
  8. }
  9. });

{top, left, bottom, right} object

If this value is an object, the left property defines the left padding. Similarly the right, top and bottom properties can also be specified. Omitted properties default to 0.

Lets say you wanted to add 50px of padding to the left side of the chart canvas, you would do:

  1. let chart = new Chart(ctx, {
  2. type: 'line',
  3. data: data,
  4. options: {
  5. layout: {
  6. padding: {
  7. left: 50
  8. }
  9. }
  10. }
  11. });

{x, y} object

This is a shorthand for defining left/right and top/bottom to same values.

For example, 10px left / right and 4px top / bottom padding on a Radial Linear Axis tick backdropPadding:

  1. let chart = new Chart(ctx, {
  2. type: 'radar',
  3. data: data,
  4. options: {
  5. scales: {
  6. r: {
  7. ticks: {
  8. backdropPadding: {
  9. x: 10,
  10. y: 4
  11. }
  12. }
  13. }
  14. }
  15. });