javascript - 图表显示十进制数字如何显示没有小数的数字?(图表.js)
问题描述
我有一个与此类似的图表,取自图表 js 站点,如果数据值较低,只需更改此图表上的数据,它将在 y 轴(标签)上显示十进制数字。像 0.0 , 1.5, 2.5 等
如何使其显示不带小数点 (.) 的 1、2、3、4、5 等数字。
图表
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>chart</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.3/dist/Chart.min.js"></script>
</head>
<body>
<canvas id="myChart" width="400" height="400"></canvas>
<script>
const ctx = document.getElementById('myChart').getContext('2d');
const myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [1, 2, 3, 4, 5, 1],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
</script>
</body>
</html>
解决方案
推荐阅读
- json - jq不是写变量的值而是变量名的实际文本
- c# - 如何在 C# 中调用报告服务器?
- c# - 如何使用 C# 在棋盘上绘制圆形棋子?
- celery - Python celery flower no monitor tab (no real-time grohics)
- python - 我想显示从 500 天前到 2020 年 12 月 31 日的预测图,但这是错误的。我的论文真的需要帮助
- android - 使用 qemu 在 arm64 上虚拟化 Android
- flutter - Flutter 墨水图像飞溅
- c++ - 无符号转换“int”到“无符号字符”
- ios - 在数据存储中保存项目 (Swift)
- javascript - (新手) React Sandbox, .js 和 html 文件