我想知道是否可以在chart.js中显示轴的最大值,即使数据还没有达到它?我正试图得到一个充满异步数据的图。我知道如何"更新"它,它工作得很好,但图表从一开始就很直观。
使用suggestedMax
(对于线性图表(:
https://www.chartjs.org/docs/latest/axes/cartesian/linear.html#axis-范围设置
例如:
ticks: {
suggestedMax: 100
}
/* data */
var data = {
labels: ["Africa", "Asia", "Europe", "America"],
datasets: [{
/* data */
label: "Data label",
backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f", "violet"],
data: [5.0,6.7,7.5, 8.6, 3.3, 4.4, 4.5]
}]
};
var options = {
responsive: true,
title: {
text: 'Hello',
display: true
},
scales: {
xAxes: [{
stacked: false,
ticks: {
},
}],
yAxes: [{
stacked: true,
ticks: {
suggestedMax: 100
}
}]
}
};
var myChart = new Chart(document.getElementById("chart"), {
type: 'bar',
data: data,
options: options
});
<canvas id="chart"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
堆叠:https://www.chartjs.org/docs/latest/charts/bar.html#stacked-条形图
相关StackOverflow Q:如何设置Y轴的最大值和最小值