score:1

this is because the object names of your scales become the id, and since you try to map your datasets to non existent scale id's it creates them for you extra. if you make the axisid prop in your dataset the same as you gave the object name it will work as inteded, see snippet:

<html>

<body>
  <canvas id="qgl_chart"></canvas>




  <script src="https://cdn.jsdelivr.net/npm/chart.js@3.1.1/dist/chart.min.js" integrity="sha256-lisrn4x2bhaafbiab0h5c7mqjli7n0sh+vrapxjiz3k=" crossorigin="anonymous"></script>

  <script>
    var ctx = document.getelementbyid("qgl_chart").getcontext('2d');
    var mychart = new chart(ctx, {
      type: 'line',
      data: {
        datasets: [{

            label: 'left dataset',
            yaxisid: 'left-y-axis',
            data: [1, 2, 3, 4]
          },
          {
            label: 'right dataset',
            yaxisid: 'right-y-axis',
            data: [4, 3, 2, 1]
          }
        ],

        labels: [1, 2, 3, 4]
      },
      options: {
        scales: {
          'left-y-axis': {
            type: 'linear',
            position: 'left'
          },
          'right-y-axis': {
            type: 'linear',
            position: 'right'
          }
        }

      }
    });
  </script>
</body>

</html>


Related Query

More Query from same tag