Newer
Older
KaiFengPC / src / views / floodSys / stationGY / lineChart.vue
@zhangdeliang zhangdeliang on 23 May 2 KB 初始化项目
<template>
  <div :id="id" style="width: 100%; height: 100%"></div>
</template>
<script>
import * as echarts from 'echarts';
import { guid } from '@/utils/ruoyi';
import { reactive, toRefs, onMounted, watch } from 'vue';
export default {
  name: 'line-chart',
  props: {
    data: Object,
  },

  setup(props) {
    const state = reactive({
      id: guid(),
      chart: null,
    });
    const resizeTheChart = () => {
      if (state.chart) {
        state.chart.resize();
      }
    };
    const init = () => {
      let chartDom = echarts.init(document.getElementById(state.id));
      var option;
      option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow',
          },
        },
        grid: {
          top: '5%',
          left: '3%',
          right: '3%',
          bottom: '5%',
          containLabel: true,
        },
        xAxis: {
          type: 'category',
          data: ['15:00', '16:00', '17:00', '18:00', '19:00', '20:00'],
          splitLine: {
            show: true,
          },
        },
        yAxis: {
          type: 'value',
          name: 'mm',
          axisLine: {
            show: true,
          },
          splitLine: {
            show: true,
            // lineStyle: {
            //   color: props.data.yAxisColor,
            //   width: 1,
            //   type: "solid",
            // },
          },
        },
        series: [
          {
            name: '泵房水位',
            data: [120, 200, 150, 80, 70, 110],
            type: 'line',
            showSymbol: false,
            itemStyle: {
              normal: {
                color: 'rgba(90, 194, 233, 0.27)',
                lineStyle: {
                  color: 'rgba(90, 194, 233, 0.27)',
                },
              },
            },
            // 填充区域的样式
            areaStyle: {
              normal: {
                // 填充色渐变
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  { offset: 1, color: 'rgba(255, 255, 255, 0)' },
                  { offset: 0, color: 'rgba(90, 194, 233, 1)' },
                ]),
              },
            },
          },
        ],
      };

      option && chartDom.setOption(option, true);
      state.chart = chartDom;
    };
    onMounted(() => {
      setTimeout(() => {
        init();
      });
      window.addEventListener('resize', resizeTheChart);
    });
    return {
      ...toRefs(state),
      resizeTheChart,
      init,
    };
  },
};
</script>