Chartjs-Is there a way to customise the y-axis labels of line chart based on the given coordinates in chat.js?

2👍

You can customize your y-axis labels like this:

const chartConfig = {
   type: "line",
   data: chartData,
   options: {
      responsive: true,
      maintainAspectRatio: false,
      scales: {
         revenueAxis: {
            type: 'linear',
            position: 'left',
            grid: { display: false },
            ticks: { 
               color: 'red', 
               callback: (value) => {
                   return value / 1000 + 'k';
               },
            },
            font: { family: "Garamond",},
            title: {
               text: 'Revenue in JPY',
               display: true
            }
         },
         x: {
            grid: { display: false }
         },

...rest of code

The callback function gets the value of each label and returns that divided by 1000 and adds the letter "k" at the end. (If the value somehow gets passed as a string, add a "+" in front of value)

Leave a comment