vue-动态曲线样例

<template>
  <div>
      <div id="myChart1" :style="{width: '500px', height: '300px'}">
      </div>
  </div>
</template>

<script>
let x = []
let y = []
var n = 0

import * as echarts from 'echarts'
// import http from "@/utils/http";
export default {
  name: 'my-Hello',
  data () {
    return {
      rawdata:'',
      msg: 'rawData'
    }
  },
  mounted(){
    
    this.drawLine();
    this.start();
  },
  methods: {
    
    
    drawLine(){
        var now = new Date()
        
        // var attention = Math.random()*100
        x.push((now.toLocaleTimeString().replace(/^\D*/, "")))
        y.push(this.rawdata)
        
        
        // 基于准备好的dom,初始化echarts实例
        let myChart= echarts.getInstanceByDom(document.getElementById('myChart1')); //有的话就获取已有echarts实例的DOM节点。
        if (myChart== null) { 
        myChart= echarts.init(document.getElementById('myChart1'));
       }
        // let myChart = echarts.init(document.getElementById('myChart1'));
        
        // 绘制图表
        myChart.setOption({
            title: { text: '脑电数据监测' },
            tooltip: {},
            xAxis: { 
                type:'category',             
                data: x,
                boundaryGap: true,
            },
            yAxis: {},
            series: [{
                name: '脑电',
                type: 'line',
                data: y,
            }]
        });
        
    },
    start(){
            
            this.timer = setInterval(()=>{
                this.dataGet();
                this.drawLine();
                n=n+1; //横坐标长度
                if(n>10)
                {this.dataClean();}
            },2000)
            
          
        },

    dataGet(){
       //改成http()
      http
      .GetData()
      .then((response) => {
      // this.axios.get('http://127.0.0.1:8000/lineUpdate/') 
      //   .then((response)=>{
        console.log(response.data.data.attention);
        this.rawdata=response.data.data.attention; //改成读取的脑电数据
        });
    },

    dataClean(){
      x.shift();
      y.shift();
    }

    

  }
}
</script>

<style>

</style>

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值