I am implementing admin dashboard that will show information about CPU usage个
因此,我需要显示y轴上0-100(百分比)的值范围,但当我try 实现这一点时,图表会动态更改y轴值,而不是静态的0-100
javascript
个
new Chart(document.querySelector('#lineChart'), {
type: 'line',
data: {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
label: 'Line Chart',
data: [20, 30, 80, 15, 5, 4, 55],
fill: true,
borderColor: 'rgb(75, 192, 192)',
tension: 0.1
}]
},
options: {
scales: {
y: {
type: 'linear',
ticks: {
beginAtZero: true,
stepSize: 20, // Customize the step size if needed
min: 0,
max:100,
suggestedMax: Math.max(maxValue,100), // Set the maximum value of the y-axis to 100
},
}
}
}
});
html
个
<canvas id="lineChart" style="max-height: 400px; display: block; box-sizing: border-box; height: 234px; width: 469px;" width="469" height="234"></canvas>