[Chartjs]-End x-axis on last data point (scatter plot) for x,y numeric values

2๐Ÿ‘

โœ…

I solved this on a similar project using xAxe.ticks.min / max attributes.

In your case, something like this should do the trick:

if (elevation[0]){
    var minX = elevation[0]['x'];
    var maxX = elevation[elevation.length -1]['x'];
}

myLineChart = new Chart(ctx, {
  type: 'scatter',
  data: {
      datasets: [{
          label: "Elevation Profile",
          data: elevation,
          showLine: true
      }]
  },
  options: {
    ...
    scales: {
      xAxes: [{
        ticks:{
          min: minX,
          max: maxX,
        }
      }]
    },
    ...
  }
});

Leave a comment