Chart.js Line Chart Stacked: Repeat left Y-Axis on the right

Viewed 23

I want to have the same y axis from the left also on the right of the chart with exactly the same scale. I am using a stacked line chart and i create multiple axis. The result i get is, that the right y-axis has a different scale (0 - 1) than the left one (0 - 6000). The data is dynamic and the scale can also be e.g. 0-10000 or 0-1000 or 0-100 etc.

    scales: {
      'left-y-axis': {
        type: 'linear',
        stacked: true,
        position: 'left',
      },
      'right-y-axis': {
        type: 'linear',
        position: 'right',
      },
    },

I have create a jsfiddle with my example, where you see that the left and right y-axis differ: https://jsfiddle.net/3yk4wfag/5/

I did try the stacked: true, for the right-y-axis, but that did not work. Is it possible to get the same scale on the right anyhow?

1 Answers

If the data is static as in your code, you can define the options min and max on 'right-y-axis' as follows:

'right-y-axis': {
   min: 0,
   max: 6000,
   type: 'linear',
   position: 'right',
 },
Related