elkers
2025-01-16 0b62eca817d6c40c188dc72c3034835a61a30a35
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!--
 * @Author: Liuyi candymxq888@outlook.com
 * @Date: 2024-07-22 09:07:29
 * @LastEditors: Liuyi candymxq888@outlook.com
 * @LastEditTime: 2024-07-31 17:08:56
 * @FilePath: \water-pipenet-web\src\views\DMA\pressure\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div>
      <div id="eChart" style="width:95%; height:350px;"></div>
    </div>
</template>
 
  <script setup>
  import * as echarts from 'echarts'
  import { onMounted } from 'vue';
  const props = defineProps({
    modelValue:{
        type:Array,
        default:[],
        required:true,
    },
    title:{
      type:String,
        default:'',
        required:true
    }
  })
  const dataList = ref(props.modelValue)
  /**
   * Echarts 图表
   */
  let myChart
  let options
  //初始化Echarts
  let initCharts = () =>{
      let chartDom = document.getElementById('eChart');
      myChart = echarts.init(chartDom);
  }
  //设置Echarts配置项
  const setEchartsOptions = () =>{
    let data = JSON.parse(JSON.stringify(dataList.value)); 
    // console.log('子Options',data);
    options = {
        title: {
          left:'3%',
          text: props.title,
          textStyle:{
            fontSize:18,
            color:'#196FE1',
            fontWeight:400
          }
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
            type: 'line' ,
            lineStyle:{
                color:'#f3eadc',
              },
              snap:true,
                      },
        },
        grid: {
        left:'5%',
        bottom: '10%'
      },
        dataset: {
          source:data
        },
        xAxis: {
          name:'上传时间',
          boundaryGap:false,
          type: 'category',
          axisPointer:{
            animation:true,
            animationEasing:'cubicOut',
            animationDuration:5000
          }
        },
        yAxis: {
          type: 'value',
          boundaryGap:false,
        },
        series: [
          {
            name: 'pressure',
            type: 'line',
            symbol: 'none',
            animationDuration: 1500,
            animationEasing: 'sinusoidalInOut',
            itemStyle: {
              color: 'none'
            },
            smooth:true,
            encode: {
              x: 0,
              y: 1
            },
            areaStyle: {
              color: new echarts.graphic.LinearGradient(  
                      0, 0, 0, 1,  
                      [  
                          {offset: 0, color:'#ff3200'},  
                          {offset: 0.2, color:'#ff0000'},  
                          {offset: 1, color:'#ff6300'}   
                      ]  
                  )  
            }
          }
        ],
        animation: true ,
    }
    myChart.clear()
    myChart.setOption(options,true)
  }
  watchEffect(() =>{
    dataList.value = props.modelValue
          if(myChart){
            setEchartsOptions()   
          }else{
            console.log('myChart不存在',myChart);   
          }
})
  onMounted(() =>{
    initCharts()
                setEchartsOptions()   
            })
  onBeforeUnmount(() =>{  
    if (myChart && myChart.dispose){  
      myChart.dispose();  
      myChart = null;  
    }
    })
  </script>
  
  <style lang="scss" scoped>
  #pressure{
    box-shadow: 0 0 15px 2px #e8e9ec;
    border-radius: 10px;
    margin: 20px auto;
  }
  </style>