Chart.js 带有百分比值的条形图比值、百分、条形图、Chart

2023-09-07 11:45:35 作者:平行世界

I want to make a chart which has percentage values on y-axis but I'm not able to find any options in document. Please suggest some answers

解决方案

You could do something like this:

JavaScript 图表LightningChart完整指南

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',
      },
    },
  ],
},

 
精彩推荐