- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试向 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
}
}
}
}
});
数据是动态添加的,但是图表一加载页面就显示问题,所以不是数据的问题。
最佳答案
没关系,我发现了问题。问题是我正在使用 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/
我想按照以下规则格式化和显示 Double: If there are more than 2 fractional digits, display it as 6 significant figur
我尝试使用 toLocaleString() 来格式化我的号码,但它做不到。 var number = 123.456; console.log(number.toLocaleString('en-G
我有这个代码: 10.00000001.toLocaleString('en-GB', {useGrouping: true, minimumFractionDigits: 2}) 我希望它返回'10
我正在尝试向 Chart.js 图表的 X 轴添加标题,但是当我将标题属性放在 x 轴上时,出现错误 Uncaught RangeError: minimumFractionDigits value
我是一名优秀的程序员,十分优秀!