我有一个动态图表更新数据每100毫秒左右。我知道我的数字将在0到100之间,但动态图表不断调整范围。我如何保持一个恒定的Y轴范围,从0到100,以便一切都可以看到比例?
代码如下:
function scoreGraphSetup() {
// Global vars used:
// scoreBuffer, latestScore
//var scoreBuffer = []; // dataPoints
var chart = new CanvasJS.Chart("chartContainer", {
title :{
text: "Motion Score (last few seconds)"
},
data: [{
type: "line",
dataPoints: scoreBuffer
}],
axisY: {
prefix: "",
suffix: "",
includeZero: false
// I need to do something in axisY, right?
},
});
var xVal = 0;
var yVal = 0;
var updateInterval = 100;
var dataLength = 150; // number of dataPoints visible at any point
var updateChart = function (count) {
count = count || 1;
for (var j = 0; j < count; j++) {
//yVal = yVal + Math.round(5 + Math.random() *(-5-5));
scoreBuffer.push({
x: xVal,
y: latestScore // push on the latest analysis score //formerly: yVal
});
xVal++;
}
if (scoreBuffer.length > dataLength) {
scoreBuffer.shift();
}
chart.render();
};
updateChart(dataLength);
setInterval(function(){updateChart()}, updateInterval);
}
发布于 2020-12-05 02:33:06
从溃疡病固定y轴min和最大值
maximum:number设置轴上允许的最大值。大于最大值的值将被裁剪。极大值还设置上限,同时平移图表。 默认:根据数据自动计算 示例:100,350. Notes:如果未设置最大值,则自动计算。在设置最大值时,应注意最大值应大于最小值。
根据你的例子:
axisY:{
minimum: 0,
maximum: 100
},
由于范围以外的值(0-100)是“裁剪”的,所以您希望添加一个固定的或算法上的最小-最大值边界,允许最终用户看到数据值已经达到或超过了。
发布于 2022-09-06 13:33:19
axisY:{ use: 1000 },//使用最大值来更改y轴值
https://stackoverflow.com/questions/65138035
复制相似问题