Cartesian Axes

Axes that follow a cartesian grid are known as 'Cartesian Axes'. Cartesian axes are used for line, bar, and bubble charts. Four cartesian axes are included in Chart.js by default.

Common Configuration

All of the included cartesian axes support a number of common options.

NameTypeDefaultDescription
typestringType of scale being employed. Custom scales can be created and registered with a string key. This allows changing the type of an axis for a chart.
positionstringPosition of the axis in the chart. Possible values are: 'top', 'left', 'bottom', 'right'
offsetbooleanfalseIf true, extra space is added to the both edges and the axis is scaled to fit into the chart area. This is set to true for a category scale in a bar chart by default.
idstringThe ID is used to link datasets and scale axes together. more…
gridLinesobjectGrid line configuration. more…
scaleLabelobjectScale title configuration. more…
ticksobjectTick configuration. more…

Tick Configuration

The following options are common to all cartesian axes but do not apply to other axes.

NameTypeDefaultDescription
autoSkipbooleantrueIf true, automatically calculates how many labels can be shown and hides labels accordingly. Labels will be rotated up to maxRotation before skipping any. Turn autoSkip off to show all labels no matter what.
autoSkipPaddingnumber0Padding between the ticks on the horizontal axis when autoSkip is enabled.
labelOffsetnumber0Distance in pixels to offset the label from the centre point of the tick (in the x direction for the x axis, and the y direction for the y axis). Note: this can cause labels at the edges to be cropped by the edge of the canvas
maxRotationnumber50Maximum rotation for tick labels when rotating to condense labels. Note: Rotation doesn't occur until necessary. Note: Only applicable to horizontal scales.
minRotationnumber0Minimum rotation for tick labels. Note: Only applicable to horizontal scales.
mirrorbooleanfalseFlips tick labels around axis, displaying the labels inside the chart instead of outside. Note: Only applicable to vertical scales.
paddingnumber0Padding between the tick label and the axis. When set on a vertical axis, this applies in the horizontal (X) direction. When set on a horizontal axis, this applies in the vertical (Y) direction.

Axis ID

The properties dataset.xAxisID or dataset.yAxisID have to match the scale properties scales.xAxes.id or scales.yAxes.id. This is especially needed if multi-axes charts are used.

  1. var myChart = new Chart(ctx, {
  2. type: 'line',
  3. data: {
  4. datasets: [{
  5. // This dataset appears on the first axis
  6. yAxisID: 'first-y-axis'
  7. }, {
  8. // This dataset appears on the second axis
  9. yAxisID: 'second-y-axis'
  10. }]
  11. },
  12. options: {
  13. scales: {
  14. yAxes: [{
  15. id: 'first-y-axis',
  16. type: 'linear'
  17. }, {
  18. id: 'second-y-axis',
  19. type: 'linear'
  20. }]
  21. }
  22. }
  23. });

Creating Multiple Axes

With cartesian axes, it is possible to create multiple X and Y axes. To do so, you can add multiple configuration objects to the xAxes and yAxes properties. When adding new axes, it is important to ensure that you specify the type of the new axes as default types are not used in this case.

In the example below, we are creating two Y axes. We then use the yAxisID property to map the datasets to their correct axes.

  1. var myChart = new Chart(ctx, {
  2. type: 'line',
  3. data: {
  4. datasets: [{
  5. data: [20, 50, 100, 75, 25, 0],
  6. label: 'Left dataset',
  7. // This binds the dataset to the left y axis
  8. yAxisID: 'left-y-axis'
  9. }, {
  10. data: [0.1, 0.5, 1.0, 2.0, 1.5, 0],
  11. label: 'Right dataset',
  12. // This binds the dataset to the right y axis
  13. yAxisID: 'right-y-axis'
  14. }],
  15. labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
  16. },
  17. options: {
  18. scales: {
  19. yAxes: [{
  20. id: 'left-y-axis',
  21. type: 'linear',
  22. position: 'left'
  23. }, {
  24. id: 'right-y-axis',
  25. type: 'linear',
  26. position: 'right'
  27. }]
  28. }
  29. }
  30. });