Chartjs-Graph of driver's times in karting races

0👍

You can use chart.js. You sort it and display it like this for example:

const ctx = document.getElementById('myChart');



let sorted = [{'Driver': 'JAN', 'LapTime': 97379}, {'Driver': 'PED', 'LapTime': 93996}].sort((a,b) => a.LapTime - b.LapTime)


  new Chart(ctx, {
    type: 'bar',
    data: {
      labels: sorted.map(s => s.Driver),
      datasets: [{
         label: "Seconds",
         data: sorted.map(s => s.LapTime / 1000),
         borderWidth: 1
      }],
    },
    options: {
      scales: {
        y: {
          beginAtZero: true
        }
      }
    }
  });
  
  
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<div>
  <canvas id="myChart"></canvas>
</div>

Leave a comment