Newer
Older
Nanping_sponge_HHDP / src / views / Sponge_screen / components / home / rightComp / footLeft.vue
@liyingjing liyingjing on 25 Oct 2023 3 KB 海绵大屏
<template>
  <div>
    <div ref="assetEchart" class="asset_echart"></div>
  </div>
</template>
<script lang="ts" setup>
import { init } from 'echarts';
import { reactive, toRefs, Ref, ref, onMounted, watchEffect, defineProps } from 'vue';
const assetEchart: Ref<HTMLElement | null | any> = ref(null);
let {
  yData,
  bottom,
  xData,
  data: { titleArray, defaultData,  colorList },
} = defineProps(['data','bottom','xData','yData']);
console.log("xData", xData)
console.log("yData", yData)
// const all = xData.reduce((n, v) => {
//   return n + v.value;
// }, 0);
const initM = () => {
  const chart = init(assetEchart.value as HTMLElement);
  window.addEventListener('resize', () => {
    chart.resize();
  });
  chart.setOption({
    grid: {
      top: '0%',
      right: '0%',
      left: '-10%',
      bottom:'10%',
      containLabel: true,
    },
    tooltip: {
      show: true,
      trigger: 'axis',
      axisPointer: {
        type: 'shadow',
      },
      textStyle: {
        fontSize: 12,
      },
      formatter: function (params) {
        let dom = `${params[0].name}
              <br/>`;
        for (let i of params) {
          dom += `${i.marker}
              ${i.seriesName}
                : 
              ${i.value}
              <br/>`;
        }
        return dom;
      },
    },
    legend: {
      show: false,
      itemWidth: 14,
      top: '0',
      left: 'center',
      data: titleArray,
      textStyle: {
        color: '#fff',
      },
    },
    xAxis: [
      {
        type: 'category',
        color: '#fff',
        data: xData,
        axisLabel: {
          margin: 10,
          color: '#fff',
          textStyle: {
            fontSize: 13,
          },
        },
        axisLine: {
          lineStyle: {
            color: '#fff',
          },
        },
        axisTick: {
          show: true,
          lineStyle: {
            color: '#fff',
          },
        },
      },
    ],
    yAxis: [
      {
        min: 0,
        show: false,
        axisLabel: {
          color: '#fff',
          textStyle: {
            fontSize: 16,
          },
        },
        axisLine: {
          lineStyle: {
            color: '#fff',
          },
        },
        axisTick: {
          show: false,
        },
        splitLine: {
          lineStyle: {
            color: '#fff',
            type: 'dashed',
          },
        },
      },
    ],
    series: [
      {
        name: titleArray[0],
        type: 'bar',
        data: yData,
        barWidth: '30px',
        itemStyle: {
                normal: {
                  color: function(params) {
                            return colorList[params.dataIndex]
                        },
                    barBorderRadius: [0, 0, 0, 0],
                }
            }
      },
    ],
  });
};
function chartSize(container, charts) {
  function getStyle(el, name) {
    if (window.getComputedStyle) {
      return window.getComputedStyle(el, null);
    } else {
      return el.currentStyle;
    }
  }
  const hi = getStyle(container, 'height').height;
  charts.style.height = hi;
}
watchEffect(() => {});
onMounted(() => {
  initM();
});
</script>

<style lang="scss" scoped>
.asset_echart {
  width: 418px;
  height: 136px;
  // margin: 10px 14px 0 16px;
  &_echart {
    width: 100%;
    height: 100%;
  }
}
</style>