Newer
Older
Nanping_sponge_HHDP / src / views / Sponge_screen / components / home / leftComp / top.vue
@liyingjing liyingjing on 25 Oct 2 KB 海绵大屏
<template>
  <div ref="assetEchart" class="asset_echart"></div>
</template>
<script lang="ts" setup>
import { init } from "echarts";
import { reactive, toRefs, Ref, ref, onMounted, watchEffect } from "vue";
const assetEchart: Ref<HTMLElement | null | any> = ref(null);
let {
  data: { type, xData, center, padding, itemStyle, x, y, subtext },
} = defineProps(["data"]);
console.log("xData", xData);
const all = xData.reduce((n, v) => {
  return n + v.value * 1;
}, 0);
const initM = () => {
  const chart = init(assetEchart.value as HTMLElement);
  window.addEventListener("resize", () => {
    chart.resize();
  });
  chart.setOption({
    title: {
      text: all + "(个)",
      subtext,
      x,
      y,
      textStyle: {
        fontSize: 14,
        fontWeight: "normal",
        color: "#333",
      },
      subtextStyle: {
        fontSize: 20,
        fontWeight: "normal",
        align: "center",
        color: "#555",
      },
    },
    tooltip: {
      formatter: (params) => {
        return (
          params.name +
          ": " +
          params.value +
          "(个)" +
          "<br/>" +
          ((params.value / all) * 100).toFixed(2) +
          "%"
        );
      },
      padding: [10, 10],
      axisPointer: {
        type: "shadow",
        shadowStyle: {
          color: "rgba(67,100,247,0.08)",
        },
      },
    },
    legend: {
      icon: "rect",
      align: "left",
      orient: "vertical",
      x: "240",
      y: "80",
      padding,
      formatter: function (name) {
        const val = xData.filter((item) => {
          return item.name === name;
        });
        return name + "         " + (val[0].value / all).toFixed(4) * 100 + "%";
      },
    },

    series: [
      {
        avoidLabelOverlap: 10,
        label: {
          show: false, // 设置为false,否则会重复
        },
        emphasis: {
          label: {
            show: false, // 显示
          },
        },
        labelLine: {
          show: false,
        },
        type,
        //  name: xData[0].name,
        radius: ["60%", "80%"],
        center,
        data: xData,
        itemStyle,
      },
    ],
  });
};
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: 120px;
  height: 200px;
  &_echart {
    width: 100%;
    height: 100%;
  }
}
</style>