我正在尝试使用Chart.js2中的圆环图显示一些数据.
我目前的图表如下所示:
我想要的输出必须显示另一个属性,即百分比,如下所示:
我已经阅读了文档,但我无法应对这一点,因为它非常通用,我是JavaScript的新手.
我的第一个图表的代码如下:
const renderCashCurrencyPie = (cashAnalysisBalances) => {
if (cashAnalysisBalances) {
const currenciesName = cashAnalysisBalances
.map(curName => curName.currency);
const availableCash = cashAnalysisBalances
.map(avCash => avCash.availableCash);
let currenciesCounter = 0;
for (let i = 0; i < currenciesName.length; i += 1) {
if (currenciesName[i] !== currenciesName[i + 1]) {
currenciesCounter += 1;
}
}
const currenciesData = {
labels: currenciesName,
datasets: [{
data: availableCash,
backgroundColor: [
'#129CFF',
'#0C6DB3',
'#FF6384',
'#00FFFF'
],
hoverBackgroundColor: [
'#FF6384',
'#36A2EB',
'#FFCE56',
'#00FFFF'
] …Run Code Online (Sandbox Code Playgroud) 原谅我有时候我的英语很差.荷兰语是我的母语.
我已经创建了一个Chart.js线图,它显示了我的主电源智能电表报告的能量使用情况.我得到它几乎像我想要的方式工作,但有一件事我无法让它以我想要的方式工作,因为我不懂一点.
在主题"Chart.js V2:为工具提示标签添加前缀或后缀 "的用户"iecs"的帮助下,我能够在工具提示处更改标签.它现在很好地显示了我想要的前缀和后缀:
tooltips: {
enabled: true,
mode: 'single',
backgroundColor: 'rgba(0,0,0,0.9)',
titleFontSize: 14,
titleFontStyle: 'bold',
titleFontColor: "#FFF",
bodyFontSize: 12,
bodyFontStyle: 'normal',
bodyFontColor: "#FFF",
footerFontSize: 12,
footerFontStyle: 'normal',
footerFontColor: "#FFF",
cornerRadius: 5,
callbacks: {
label: function(tooltipItems, data) { // Solution found on https://stackoverflow.com/a/34855201/6660135
//Return value for label
return 'Usage: ' + tooltipItems.yLabel*1000 + ' watt';
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试添加完全相同的代码来修改我undefined在应该显示日期和时间的地方的标题时:
tooltips: {
enabled: true,
mode: 'single',
backgroundColor: 'rgba(0,0,0,0.9)',
titleFontSize: 14,
titleFontStyle: 'bold',
titleFontColor: "#FFF",
bodyFontSize: 12,
bodyFontStyle: …Run Code Online (Sandbox Code Playgroud) 如何编辑chartjs工具提示以在工具提示中添加自定义字符串

例如:我想更改"1月:28个文件"或"28个文件"之类的工具提示
如何在悬停在条形图上时将单位添加到标签中?我查看了文档,但找不到答案.
http://www.chartjs.org/docs/#bar-chart

我想添加例如(mm,°C,)我的代码:
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:false
},
scaleLabel: {
display: true,
labelString: 'Temperature'
}
}]
},
title: {
display: true,
text: 'Temperature'
},
tooltips:{
enabled: true,
mode: 'label'
}
}
});
datasets: [
{
label: "Temperature",
type: "line",
backgroundColor: "transparent",
borderColor: "#C72448",
pointBackgroundColor: "#C72448",
pointBorderColor: "#fff",
pointHoverBackgroundColor: "#fff",
pointHoverBorderColor: "rgba(179,181,198,1)",
data: [19,20,21,24,27,29,30,31,30,28,25,21]
}
Run Code Online (Sandbox Code Playgroud)