本实践主要测试一下在低版本鸿蒙,仅支持FA模型JS语言的环境中,如何实现心电波形的绘制,动态刷新以及多个波形的绘制过程,仅讨论了上层实现过程,底层数据采集部分不涉及。
整个界面分为上下两部分,上部分显示时间和心率,通过定时器setInterval不断刷新。下部分显示波形图,这里模拟的是三个导联设备,所以画了三个波形图,每个波形图使用一个chart组件,共放置了三个chart组件。
export default {
data: {
dataArray: [45, 45, 45, 46, 46, 46, 46, 47, 47, 47, 47, 46, 46, 46, 46, 46, 46, 45, 45, 45, 44, 44, 45, 49, 73, 94, 97, 80, 51, 43, 42, 43, 43, 43, 43, 43, 43, 43, 43, 43, 44, 44, 44, 44, 44, 45, 45, 45, 45, 46, 46, 47, 47, 48, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 55, 54, 53, 52, 50, 48, 47, 45, 44, 44, 43, 43, 43, 43, 43, 43, 44, 44, 44, 44, 45, 45, 45, 46, 46, 46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 47],
firstArray: [45, 45, 45, 46, 46, 46, 46, 47, 47, 47, 47, 46, 46, 46, 46, 46, 46, 45, 45, 45, 44, 44, 45, 49, 73, 94, 97, 80, 51, 43, 42, 43, 43, 43, 43, 43, 43, 43, 43, 43, 44, 44, 44, 44, 44, 45, 45, 45, 45, 46, 46, 47, 47, 48, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 55, 54, 53, 52, 50, 48, 47, 45, 44, 44, 43, 43, 43, 43, 43, 43, 44, 44, 44, 44, 45, 45, 45, 46, 46, 46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 47],
secondArray: [45, 45, 45, 46, 46, 46, 46, 47, 47, 47, 47, 46, 46, 46, 46, 46, 46, 45, 45, 45, 44, 44, 45, 49, 73, 94, 97, 80, 51, 43, 42, 43, 43, 43, 43, 43, 43, 43, 43, 43, 44, 44, 44, 44, 44, 45, 45, 45, 45, 46, 46, 47, 47, 48, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 55, 54, 53, 52, 50, 48, 47, 45, 44, 44, 43, 43, 43, 43, 43, 43, 44, 44, 44, 44, 45, 45, 45, 46, 46, 46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 47],
thirdArray: [45, 45, 45, 46, 46, 46, 46, 47, 47, 47, 47, 46, 46, 46, 46, 46, 46, 45, 45, 45, 44, 44, 45, 49, 73, 94, 97, 80, 51, 43, 42, 43, 43, 43, 43, 43, 43, 43, 43, 43, 44, 44, 44, 44, 44, 45, 45, 45, 45, 46, 46, 47, 47, 48, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 55, 54, 53, 52, 50, 48, 47, 45, 44, 44, 43, 43, 43, 43, 43, 43, 44, 44, 44, 44, 45, 45, 45, 46, 46, 46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 47],
dataIndex : 0,
firstIndex : 0,
secondIndex : 0,
thirdIndex : 0,
timeValue: "15:50:24",
heartBeatValue: "75",
chartInterval: '',
timeInterval: '',
heartData: [70, 78, 80, 89, 90, 85, 95, 99, 101, 106, 118],
lineData: [
{
strokeColor: '#3fce3f',
fillColor: '#b7f5b7',
data: [50],
gradient: false,
}
],
lineOps: {
xAxis: {
min: 0,
max: 400,
display: false,
},
yAxis: {
min: 0,
max: 200,
display: false,
},
series: {
lineStyle: {
width: "3px",
smooth: true,
},
headPoint: {
shape: "circle",
size: 6,
strokeWidth: 4,
fillColor: '#ffffff',
strokeColor: '#ffffff',
display: true,
},
loop: {
margin: 20,
gradient: true,
}
}
},
},
onInit() {
console.log("onInit was called.")
this.setChartInterval();
this.setTimeInterval();
},
onHide(){
clearInterval(this.chartInterval);
clearInterval(this.timeInterval);
},
setChartInterval() {
var that = this
this.chartInterval = setInterval(function() {
that.$refs.firstchart.append({
serial: 0,
data: [that.firstArray[that.firstIndex++ % 100]]
})
that.$refs.secondchart.append({
serial: 0,
data: [that.secondArray[that.secondIndex++ % 100]]
})
that.$refs.thirdchart.append({
serial: 0,
data: [that.thirdArray[that.thirdIndex++ % 100]]
})
}, 50);
},
setTimeInterval() {
var that = this
this.timeInterval = setInterval(function() {
var myDate = new Date();
var hh = myDate.getHours();
if(hh < 10)
hh = "0" + hh;
var mm = myDate.getMinutes();
if(mm < 10)
mm = "0" + mm;
var ss = myDate.getSeconds();
if(ss < 10)
ss = "0" + ss;
that.timeValue = hh + ":" +mm + ":" + ss;
that.heartBeatValue = that.heartData[Math.floor(Math.random() * that.heartData.length)];
}, 1000);
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
在JS中通过chart组件绘制波形,发现是非常方便的,chart组件对数据的更新很友好,直接向数据源中不断push新数据就可以了,而且绘图时,控件会自动清空历史波形,视觉体验更好,开发方面也更方便。通过测试发现,波形数量增加时,也会出现卡顿现象,如果以后加上底层数据采集,可能对硬件性能也有一定要求。