我成功地为传感器运行了数据记录Web服务器,但是由于AJAX,图形上的X轴继续记录。我打算将X轴缩短到几秒钟,并擦除时间间隔之前记录的先前数据,以使信号更清晰。
有人有什么建议吗?
<script>
var values = [];
var timeStamp = [];
function showGraph()
{
for (i = 0; i < arguments.length; i++) {
values.push(arguments[i]);
}
var ctx = document.getElementById("Chart").getContext('2d');
var Chart2 = new Chart(ctx, {
type: 'line',
data: {
labels: timeStamp, //Bottom Labeling
datasets: [{
label: "Voltage",
fill: false, //Try with true
backgroundColor: 'rgba( 243, 156, 18 , 1)', //Dot marker color
borderColor: 'rgba( 243, 156, 18 , 1)', //Graph Line Color
data: values,
}],
},
options: {
title: {
display: true,
text: "Voltage"
},
maintainAspectRatio: false,
elements: {
line: {
tension: 0.5 //Smoothening (Curved) of data lines
}
},
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
}