简体   繁体   English

Chart.js - y轴自定义标签

[英]Chart.js - y axis custom label

I have simple line graph which is show some progress. 我有简单的线图,显示了一些进展。 There are dates on x-axis a and status (1 to 5) on y-axis. 在x轴上有日期,在y轴上有状态(1到5)。 Data will always be from 1 to 5. But what I need is to change labels on y-axis (and labels on point hover too) from numbers to showing progress by text string. 数据总是从1到5.但我需要的是从数字更改y轴上的标签(以及点悬停时的标签)以显示文本字符串的进度。 For example where is 1 a I need text string with "request added", on 2 "request viewed", on 3 "request accepted" on 4 "request solved" and on 5 "solving confirmed". 例如,在哪里是1 a我需要带有“请求添加”的文本字符串,2“请求已查看”,3“请求已接受”,4“请求已解决”和5“解决已确认”。 I think there is no native way to achieve this, but maybe someone will know how to edit Chart.js to make it. 我认为没有本地方法可以实现这一点,但也许有人会知道如何编辑Chart.js来实现它。

Here is a picture how it looks now, with these number: screenshot 这是一张现在看起来如何的照片,有这些数字: 截图

Sorry for my english and thx for any help! 对不起我的英文和thx任何帮助!

You can use the scaleLabel function. 您可以使用scaleLabel函数。 Have a look here https://stackoverflow.com/a/28700578/909535 看看这里https://stackoverflow.com/a/28700578/909535

scaleLabel: function (valuePayload) {
if(Number(valuePayload.value)===1)    
return 'request added';
if(Number(valuePayload.value)===2)    
return 'request viewed';
if(Number(valuePayload.value)===3)    
return 'request accepted';
if(Number(valuePayload.value)===4)    
return 'request solved';
if(Number(valuePayload.value)===5)    
return 'solving confirmed';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM