ali
2024-09-03 0ae83a895e80a4b9777a27f613d721a7e5e2ac18
energy_management_ui/src/views/energyPlan/energyMonitoring/LineChart.vue
@@ -3,128 +3,137 @@
</template>
<script>
  import echarts from 'echarts'
  require('echarts/theme/macarons')
  import resize from '../../dashboard/mixins/resize'
  const animationDuration = 6000
import echarts from "echarts";
require("echarts/theme/macarons");
import resize from "../../dashboard/mixins/resize";
const animationDuration = 6000;
  export default {
    mixins: [resize],
    props: {
      className: {
        type: String,
        default: 'chart'
      default: "chart"
      },
      width: {
        type: String,
        default: '100%'
      default: "100%"
      },
      height: {
        type: String,
        default: '350px'
      default: "350px"
      },
      chartData: {
        type:Object,
      type: Object
      }
    },
    watch: {
      chartData: {
        deep: true,
        handler(val) {
          this.setOptions(val)
        this.setOptions(val);
        }
      }
    },
    data() {
      return {
        chart: null,
        seriesData: [],
      }
      seriesData: []
    };
    },
    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,expecteData} = {}) {
        this.chart.setOption({
          tooltip: {
            trigger: 'axis',
            axisPointer: { // 坐标轴指示器,坐标轴触发有效
              type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器,坐标轴触发有效
            type: "shadow" // 默认为直线,可选为:'line' | 'shadow'
            }
          },
          title: {
            x: 'center',
            y: 'top',
          x: "center",
          y: "top",
            textStyle: {
              color: "#333"
            },
            color: "#fff"
          }
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: { // 坐标轴指示器,坐标轴触发有效
              type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器,坐标轴触发有效
            type: "shadow" // 默认为直线,可选为:'line' | 'shadow'
            }
          },
          grid: {
            top: 40,
            left: '2%',
            right: '2%',
            bottom: '3%',
          left: "2%",
          right: "2%",
          bottom: "3%",
            containLabel: true
          },
          /*legend: {
            data:['',''],
            left: '60%',
          },*/
          xAxis: [{
            type: 'category',
        xAxis: [
          {
            type: "category",
            data: actualData,
            axisPointer: {
              type: 'shadow'
              type: "shadow"
            }
          }],
          yAxis: [{
          }
        ],
        yAxis: [
          {
            //name: '综合能耗',
            type: 'value',
            type: "value",
            nameTextStyle: {
              color: "#333",
              color: "#333"
            },
            axisLabel: {
              formatter: '{value}'
              formatter: "{value}"
            },
            axisTick: {
              show: false
            },
          }],
          series: [{
            }
          }
        ],
        series: [
          {
            //name:"综合能耗",
            type: 'bar',
            type: "bar",
            data: expectedData,
            //stack: 'vistors',
            animationDuration: 2800,
            animationEasing: 'quadraticOut'
          },{
            animationEasing: "quadraticOut"
          },
          {
            //name:"能源占比",
            type: 'bar',
            type: "bar",
            data: expecteData,
            animationDuration: 2800,
            animationEasing: 'quadraticOut'
          }]
        })
            animationEasing: "quadraticOut"
          }
        ]
      });
      }
    }
  }
};
</script>