score:1

i used this to add percentage to yaxis-

const options = {
showlines: true,
scales: {
  yaxes: [
    {
      ticks: {
        min: 0,
        max: 100,
        stepsize: 20,
        callback: function (value) {
          return (value / this.max * 100).tofixed(0) + '%'; // convert it to percentage
        },
      },
      type: "linear",
      display: true,
      position: "left",
      id: "y-axis-1",
      gridlines: {
        drawonarea: false,
      },
    },
  ],
},

};

score:2

of using the tolocalestring function

scales: {
  yaxes: [
    {
      ticks: {
        callback: function (value) {
          return value.tolocalestring('de-de', {style:'percent'});
        },
      }
    },
  ],
},

score:2

with chart.js 3 you can do this:

const options = {
    scales: {
        y: {
            ticks: {
                format: {
                    style: 'percent'
                }
            }
        }
    }
};

score:5

don't think there is a out of the box version of that yet. you might have to do it a bit manually by calculating the percentages before setting the chart up and e.g. follow this example to create the graph: https://stackoverflow.com/a/40438511/6638478

score:6

if you have a static total...say a max value of 800, you can just show custom ticks like this:

ticks: {
    //.. other settings
    stepsize: 200, /* total/4 shows 0, 25%, 50%, 75%, 100% */             
    callback: function(value, index, values) {
        return ((value / 800) * 100) + '%';
    }
}

score:24

you could do something like this:

if you know the absolute value that represents 100% in your dataset, you can pass this to your options object:

    scales: {
  yaxes: [
    {
      ticks: {
        min: 0,
        max: this.max,// your absolute max value
        callback: function (value) {
          return (value / this.max * 100).tofixed(0) + '%'; // convert it to percentage
        },
      },
      scalelabel: {
        display: true,
        labelstring: 'percentage',
      },
    },
  ],
},

Related Query

More Query from same tag