ai-watch-app/pages/only_test/only_test.vue

80 lines
1.6 KiB
Vue

<template>
<view>
<view style=" height:600rpx;background-color: #fff;"><l-echart ref="chartRef" @finished="init"></l-echart></view>
</view>
</template>
<script>
import * as echarts from '@/uni_modules/lime-echart/static/echarts.min'
export default {
data() {
return {
op:{
title: {
text: '心电图模拟'
},
tooltip: {
trigger: 'axis'
},
xAxis: {
type: 'time',
splitLine: {
show: false
}
},
yAxis: {
boundaryGap: ['0%', '100%'],
splitLine: {
show: false
},
type: 'value',
max: 100,
min: -100
},
series: [{
name: '心电图',
type: 'line',
data: []
}]
},
}
},
onLoad() {
let _self = this;
},
methods: {
async init() {
_self.chart = await this.$refs.chartRef.init(echarts);
_self.chart.setOption(this.op)
var data = _self.op.series[0].data;
setInterval(function () {
// 随机生成新的数据,模拟心跳
var now = new Date();
var value = Math.random() * 100 - 50; // 心电图的值在[-100, 100]范围内
data.push([now, value]);
// 移除旧的数据,只保留最近的一段时间的数据
var duration = 1000 * 60 * 10; // 保留最近10分钟的数据
while (data[0] && now - data[0][0] > duration) {
data.shift();
}
_self.chart.setOption({
series: [{
data: data
}]
})
// myChart.setOption({
// series: [{
// data: data
// }]
// });
}, 1000); // 每
},
}
}
</script>
<style>
</style>