score:0

Accepted answer

your first image is as close as it can get with plain chart.js with a single scale, chart.js does not support scale breaks.

you can add a second y axis and map the datasets to different scales:

var options = {
  type: 'line',
  data: {
    labels: ["red", "blue", "yellow", "green", "purple", "orange"],
    datasets: [{
        label: '# of votes',
        data: [12000, 19000, 3000, 5000, 2000, 3000],
        bordercolor: 'orange',
        yaxisid: 'y'
      },
      {
        label: '# of points',
        data: [7, 11, 5, 8, 3, 7],
        bordercolor: 'pink',
        yaxisid: 'y2'
      }
    ]
  },
  options: {
    scales: {
      y: {
        position: 'left'
      },
      y2: {
        position: 'right'
      }
    }
  }
}

var ctx = document.getelementbyid('chartjscontainer').getcontext('2d');
new chart(ctx, options);
<body>
  <canvas id="chartjscontainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/3.7.1/chart.js"></script>
</body>

edit:
notice you are still using v2 of the lib

var options = {
  type: 'line',
  data: {
    labels: ["red", "blue", "yellow", "green", "purple", "orange"],
    datasets: [{
        label: '# of votes',
        data: [12000, 19000, 3000, 5000, 2000, 3000],
        bordercolor: 'orange',
        yaxisid: 'y'
      },
      {
        label: '# of points',
        data: [7, 11, 5, 8, 3, 7],
        bordercolor: 'pink',
        yaxisid: 'y2'
      }
    ]
  },
  options: {
    scales: {
      yaxes: [{
        id: 'y',
        position: 'left'
      }, {
        id: 'y2',
        position: 'right'
      }]
    }
  }
}

var ctx = document.getelementbyid('chartjscontainer').getcontext('2d');
new chart(ctx, options);
<body>
  <canvas id="chartjscontainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.9.4/chart.js"></script>
</body>

score:0

creating different y-axes worked fine for me, albeit partially. modify the js code to create an axis for each compared element:

var datasetsf = [];
    for (var i = 1; i < datafollowers[0].length; i++) {
      datasetsf.push(
        {
          label: datafollowers[0][i], // column name
          data: datafollowers.slice(1).map(function(row) {return row[i]}), // data in that column
          fill: false, // `true` for area charts, `false` for regular line charts
          yaxisid: 'y' + i
        }
      )
    }

well, with that modification version 2 of charts does not work as indicated. and in version 3, among other things, the colors are deconfigured as seen in the image.

imagen1

the problem is that i have many graphics and i would have to adapt the code of all the graphics to work with version 3 (which i will do but i am very new to this and it would take time to fix them all). is there any way to do the same with version 2? and how could i do so that all the axes and created would not be seen?


Related Query

More Query from same tag