Newer
Older
KaiFengPC / src / views / sponeScreen / Echarts / RainfallLegend.vue
@鲁yixuan 鲁yixuan on 20 Jun 3 KB update
<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,
    refresh: Number,
  },
  setup(props) {
    console.log(props.data);

    const allData = reactive({
      series: [],
      legend: [],
      id: guid(),
      chart: null,
    });
    const resizeTheChart = () => {
      if (allData.chart) {
        allData.chart.resize();
      }
    };

    const init = () => {
      let chartDom = echarts.init(document.getElementById(allData.id));
      var option;
      option = {
        // backgroundColor: '#0e2147',
        grid: {
          //   left: '5%',
          //   top: '5%',
          bottom: '10%',
          right: '5%',
        },
        legend: {
          type: 'scroll',
          data: '来电量',
          itemWidth: 18,
          itemHeight: 12,
          textStyle: {
            color: '#00ffff',
            fontSize: 14,
          },
        },
        yAxis: [
          {
            type: 'value',
            position: 'left',
            nameTextStyle: {
              color: '#3FFFC2',
            },
            splitLine: {
              lineStyle: {
                type: 'dashed',
                color: 'rgba(135,140,147,0.8)',
              },
            },
            axisLine: {
              show: false,
            },
            axisTick: {
              show: false,
            },
            axisLabel: {
              formatter: '{value}',

              color: '#fff',
              fontSize: 14,
            },
          },
        ],
        xAxis: [
          {
            type: 'category',
            axisTick: {
              show: false,
            },
            axisLine: {
              show: false,
              lineStyle: {
                color: '#3FFFC2',
              },
            },
            axisLabel: {
              inside: false,
              textStyle: {
                color: '#fff', // x轴颜色
                fontWeight: 'normal',
                fontSize: '14',
                lineHeight: 22,
              },
            },
            data: props.data.XName,
          },
        ],
        series: [
          {
            symbolSize: 10,

            name: '来电量',
            type: 'line',
            data: props.data.data1,
            itemStyle: {
              normal: {
                borderWidth: 5,
                // color: '#0696f9',
              },
            },
          },
          {
            name: '滑行的光点',
            type: 'lines',
            coordinateSystem: 'cartesian2d',
            symbolSize: 30,
            polyline: true,
            effect: {
              show: true,
              trailLength: 0,
              symbol: 'arrow',
              period: 30, //光点滑动速度
              symbolSize: 15,
            },
            lineStyle: {
              normal: {
                width: 1,
                opacity: 0.6,
                curveness: 0.2,
              },
            },
            data: props.data.data,
          },
        ],
      };
      option && chartDom.setOption(option, true);
      allData.chart = chartDom;
    };
    watch(
      () => props.refresh,
      () => {
        if (allData.chartDom) {
          allData.chartDom.dispose();
          allData.chartDom = null;
        }
        setTimeout(() => {
          init();
        }, 0);
      }
    );
    onMounted(() => {
      init();
      window.addEventListener('resize', resizeTheChart);
    });
    return {
      ...toRefs(allData),
      resizeTheChart,
      init,
    };
  },
};
</script>