ali
2024-09-03 0ae83a895e80a4b9777a27f613d721a7e5e2ac18
energy_management_ui/src/views/energyAlarm/historicalAlarm/LChart.vue
@@ -1,11 +1,10 @@
<template>
  <div :class="className" :style="{height:height,width:width}" />
  <div :class="className" :style="{ height: height, width: width }" />
</template>
<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
/*import resize from './mixins/resize'*/
export default {
@@ -13,15 +12,15 @@
  props: {
    className: {
      type: String,
      default: 'chart'
      default: "chart"
    },
    width: {
      type: String,
      default: '100%'
      default: "100%"
    },
    height: {
      type: String,
      default: '350px'
      default: "350px"
    },
    autoResize: {
      type: Boolean,
@@ -35,37 +34,58 @@
  data() {
    return {
      chart: null
    }
    };
  },
  watch: {
    chartData: {
      deep: true,
      handler(val) {
        this.setOptions(val)
        this.setOptions(val);
      }
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return
      return;
    }
    this.chart.dispose()
    this.chart = null
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.setOptions(this.chartData)
      this.chart = echarts.init(this.$el, "macarons");
      this.setOptions(this.chartData);
    },
    setOptions({ expectedData, actualData } = {}) {
      this.chart.setOption({
        xAxis: {
          data: ['04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00' , '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00'],
          data: [
            "04:00",
            "05:00",
            "06:00",
            "07:00",
            "08:00",
            "09:00",
            "10:00",
            "11:00",
            "12:00",
            "13:00",
            "14:00",
            "15:00",
            "16:00",
            "17:00",
            "18:00",
            "19:00",
            "20:00",
            "21:00",
            "22:00",
            "23:00"
          ],
          boundaryGap: false,
          axisTick: {
            show: false
@@ -79,9 +99,9 @@
          containLabel: true
        },
        tooltip: {
          trigger: 'axis',
          trigger: "axis",
          axisPointer: {
            type: 'cross'
            type: "cross"
          },
          padding: [5, 10]
        },
@@ -91,48 +111,100 @@
          }
        },
        legend: {
          data: ['预警值','限值']
          data: ["预警值", "限值"],
          textStyle: {
            color: "#fff"
          }
        },
        series: [{
          name: '预警值', itemStyle: {
            normal: {
              color: '#FF005A',
              lineStyle: {
                color: '#FF005A',
                width: 2,
              },
            }
          },
          smooth: true,
          type: 'line',
          data:[200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200],
          animationDuration: 1000,
          animationEasing: 'cubicInOut'
        },
        series: [
          {
            name: '限值',
            smooth: true,
            type: 'line',
            name: "预警值",
            itemStyle: {
              normal: {
                color: '#3888fa',
                color: "#FF005A",
                lineStyle: {
                  color: '#3888fa',
                  color: "#FF005A",
                  width: 2
                },
                areaStyle: {
                  color: '#f3f8ff'
                }
              }
            },
            data:[200, 200, 181, 224,210, 172, 181, 224,210, 172, 181, 224,210, 172, 181, 224,210, 172, 181, 224,210, 172, 181],
            smooth: true,
            type: "line",
            data: [
              200,
              200,
              200,
              200,
              200,
              200,
              200,
              200,
              200,
              200,
              200,
              200,
              200,
              200,
              200,
              200,
              200,
              200,
              200,
              200,
              200,
              200,
              200
            ],
            animationDuration: 1000,
            animationEasing: "cubicInOut"
          },
          {
            name: "限值",
            smooth: true,
            type: "line",
            itemStyle: {
              normal: {
                color: "#3888fa",
                lineStyle: {
                  color: "#3888fa",
                  width: 2
                },
                areaStyle: {
                  color: "#f3f8ff"
                }
              }
            },
            data: [
              200,
              200,
              181,
              224,
              210,
              172,
              181,
              224,
              210,
              172,
              181,
              224,
              210,
              172,
              181,
              224,
              210,
              172,
              181,
              224,
              210,
              172,
              181
            ],
            animationDuration: 800,
            animationEasing: 'quadraticOut'
          }]
      })
            animationEasing: "quadraticOut"
          }
        ]
      });
    }
  }
}
};
</script>