如何在 Chart.js 中使用百分比刻度

How to use percentage scale with Chart.js(如何在 Chart.js 中使用百分比刻度)

本文介绍了如何在 Chart.js 中使用百分比刻度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I tried to look it up in the documentation (all examples I found elsewhere did not work anymore, probably due to an outdated syntax for earlier versions) how to use "scaleLabel", but there it references to the scale title configuration with a link which does not exist (anymore): http://www.chartjs.org/docs/#scale-title-configuration

Can someone please provide a working example?

解决方案

Scale title configuration is a header if you scroll down in the documentation.

Here is a simple bar chart example, using scaleLabel which is sligtly modified to illustrate a percentage.

https://jsfiddle.net/r71no58a/4/

scales: {
   yAxes: [{
       ticks: {
           min: 0,
           max: 100,
           callback: function(value) {
               return value + "%"
           }
       },
       scaleLabel: {
           display: true,
           labelString: "Percentage"
       }
   }]
}

这篇关于如何在 Chart.js 中使用百分比刻度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 Chart.js 中使用百分比刻度

基础教程推荐