liuying
2025-04-28 0630126012170da25291d55f0a1bd3130e64f434
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
<template>
  <div class="box-container" id="echarts10"></div>
</template>
 
<script>
let timer = null;
export default {
  data() {
    return {
      option: {},
      myChart: {},
      currentIndex: -1,
      lineData: [],  // 添加用于存储曲线图数据的属性
    };
  },
  mounted() {
    this.myChart = this.$echarts.init(document.getElementById("echarts10"));
    
    // 生成假数据
    this.generateFakeData();
 
    this.option = {
      tooltip: {
        trigger: 'axis'
      },
      xAxis: {
        type: 'category',
        data: this.lineData.map(item => item.time) // 使用假数据中的时间作为 x 轴
      },
      yAxis: {
        type: 'value'
      },
      series: [{
        name: '状态数据',
        type: 'line',
        data: this.lineData.map(item => item.value), // 使用假数据中的值作为 y 轴
        smooth: true // 平滑曲线
      }]
    };
 
    this.myChart.setOption(this.option);
    const that = this;
    window.addEventListener("resize", () => {
      that.myChart.resize();
    });
  },
  methods: {
    generateFakeData() {
      // 生成 10 个假数据点
      const fakeData = [];
      for (let i = 0; i < 10; i++) {
        fakeData.push({
          time: `时间${i + 1}`,
          value: Math.floor(Math.random() * 100) + 1  // 随机生成 1-100 的值
        });
      }
      this.lineData = fakeData;
    },
  },
};
</script>
 
<style>
#echarts10 {
  width: 3.84rem;
}
.box-container{
  margin: 0 auto;
  display: block;
}
</style>