我正在尝试在 Chart.js v4 中制作一个简单的雷达图,以 0 为中心,6 为最高点。然而我得到的只是中心在 0 到 3 之间(取决于我在数据集中的最低值是多少),最大值在 5 到 6 之间。我有点迷失了可能导致这种情况的原因。我尝试了以下配置,将 min 0 和 max 6 以及 beginAtZero 设置为 true。有什么想法吗?谢谢
const config = {
type: 'radar',
data: {
//labels: labels,
labels: data,
datasets: [{
data: data,
backgroundColor: 'rgba(255, 255, 255, 0.36)',
borderColor: 'white',
borderWidth: 3
}]
},
options: {
plugins: {
legend: {
display: false
}
},
scales: {
r: {
angleLines: {
display: true
},
ticks: {
beginAtZero: true,
min: 0,
max: 6,
stepSize: 1,
color: 'black',
font: {
size: 20
}
},
pointLabels: {
color: 'black',
font: {
size: 20
},
backdropColor: 'rgba(255, 255, 255, 0.75)',
backdropPadding: 6
},
// Ensure that the grid lines also start from 0 if necessary
grid: {
circular: true
}
}
},
elements: {
line: {
backgroundColor: 'rgba(0, 0, 0, 0)'
}
},
}
};
const ctx = canvas.getContext('2d');
new Chart(ctx, config);
您可以使用 r:{}
var ctx = document.getElementById('myRadarChart').getContext('2d'); var myRadarChart = 新图表(ctx, { 类型:'雷达', 数据: { 标签:['访问向量'、'访问复杂性'、'身份验证'、'机密性影响'、'完整性影响'、'可用性影响']、 数据集:[{ 标签:“CVE 指标”, 数据:[3,3,3,3,3,3], 背景颜色: 'rgba(255, 159, 64, 0.2)', 边框颜色: 'rgba(255, 159, 64, 1)', 边框宽度:4, 点半径:5, 点背景颜色: 'rgba(255, 99, 132, 1)', 点边框颜色:'#fff' }] }, 选项: { 规模: { 刻度线:{ 开始于零:假, 步长:1,
},
r:{
suggestedMin: 0,
suggestedMax: 3
}
}
}
});
这是我在图表中使用最小值和最大值的代码