如何使用Chart.js的百分比比例 [英] How to use percentage scale with Chart.js

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

问题描述

我试图在文档中查找(在其他地方发现的所有示例都不再工作,可能是由于早期版本的过时语法)如何使用scaleLabel,但是它引用了缩放标题配置一个不存在的链接(不再):
http:// www。 chartjs.org/docs/#scale-title-configuration



有人可以提供一个工作示例吗?

解决方案

如果在文档中向下滚动,比例标题配置是标题。



这是一个简单的条形图示例,使用scaleLabel进行修改以说明百分比。



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

  scale:{
yAxes:[{
ticks:{
min:0,
max:100,
回调:function(value){
返回值+%
}
},
scaleLabel:{
display:true,
labelString:Percentage
}
}]
}


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的百分比比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆