score:1

Accepted answer

you can use the tickcallback to transform the value to whatever you like, easyest thing to do is make an array with all the weekdays and then use the value as an index like so:

const weekdays = ["sun", "mon", "thu", "wen", "tru", "fri", "sat"];

const options = {
  type: 'bubble',
  data: {
    datasets: [{
      label: '# of votes',
      data: [{
        x: 0,
        y: 1,
        r: 4
      }, {
        x: 1,
        y: 1,
        r: 4
      }, {
        x: 2,
        y: 1,
        r: 4
      }, {
        x: 3,
        y: 1,
        r: 4
      }, {
        x: 4,
        y: 1,
        r: 4
      }, {
        x: 5,
        y: 1,
        r: 4
      }, {
        x: 6,
        y: 1,
        r: 4
      }],
      backgroundcolor: 'pink'
    }]
  },
  options: {
    scales: {
      x: {
        ticks: {
          callback: (val) => (weekdays[val])
        }
      }
    }
  }
};

const 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.5.0/chart.js"></script>
</body>


Related Query

More Query from same tag