我正在尝试向 Chart.js 图表的 X 轴添加标题,但是当我将标题属性放在 x 轴上时,出现错误 Uncaught RangeError:minimumFractionDigits value is out of range,但它并没有如果我向 Y 轴添加标题,就会发生这种情况。
仅当我添加标题属性时才会出现问题,如果将其删除,图表将完美运行。
grafica_roi = new Chart($('#grafica_roi'), {
type: 'bar',
data: {
labels: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25'],
datasets: [{
//label: 'Beneficio obtenido',
data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
backgroundColor: '#F0A202'
}]
},
options: {
maintainAspectRatio: false,
scales: {
y: {
beginAtZero: true,
ticks: {
font: {
size:function(context) {
var width = context.chart.width;
if(width<=320) {
size = 12;
}
else {
if(width>320 && width<600) {
size = 16;
}
else {
size = 20;
}
}
//var size = Math.round(width / 32);
return size;
},
weight: "bold"
}
},
grid: {
display: false
},
title: {
text: 'Ahorro',
display: true
}
},
x: {
beginAtZero: true,
ticks: {
font: {
size:function(context) {
var width = context.chart.width;
if(width<=320) {
size = 12;
}
else {
if(width>320 && width<600) {
size = 16;
}
else {
size = 20;
}
}
//var size = Math.round(width / 32);
return size;
},
weight: "bold"
}
},
grid: {
display: false
},
//this title attribute below causes the problem
title: {
text: 'Años',
display: true
}
}
},
plugins: {
autocolors: false,
legend: {
display: false
},
title: {
display: true,
text: "Retorno de inversión",
font: {
size: 20
}
}
}
}
});
数据是动态添加的,但是图表一加载页面就显示问题,所以这与数据无关。