gpt4 book ai didi

javascript - 添加 X 轴标题导致 Uncaught RangeError : minimumFractionDigits value is out of range in Chart. js

转载 作者:行者123 更新时间:2023-12-05 04:46:17 27 4
gpt4 key购买 nike

我正在尝试向 Chart.js 图表的 X 轴添加标题,但是当我将标题属性放在 x 轴上时,出现错误 Uncaught RangeError: minimumFractionDigits value is out of range,但是它如果我向 Y 轴添加标题,则不会发生这种情况。

只有当我添加 title 属性时才会出现这个问题,如果我把它去掉,图表就可以完美运行。

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
}
}
}
}
});

数据是动态添加的,但是图表一加载页面就显示问题,所以不是数据的问题。

error chart js

最佳答案

没关系,我发现了问题。问题是我正在使用 v3.1 Chart.js,同时尝试使用 v3.5 Chart.js 中的设置。

更改了 JS 文件版本,现在它运行良好。

关于javascript - 添加 X 轴标题导致 Uncaught RangeError : minimumFractionDigits value is out of range in Chart. js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68886764/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com