echarts 左侧legend右侧饼状图标题在饼状图中间

echarts yekong

vue 数据可视化大屏 项目开发中,需要使用echarts饼状图效果。

饼状图legend在左下角

饼状图label分为两行,上面标题,下面百分比

饼状图根据数据显示不同的大小

饼状图中心显示数字以及总标题

echarts 左侧legend右侧饼状图标题在饼状图中间

演示实例

使用组件

<template>
  <div class="itemBodys">
    <echarts :list="list"></echarts>
  </div>
</template>

<script>
import echarts from "./components/echarts.vue";
export default {
  data() {
    return {
      list: [{
        name: '未执行',
        value: 10
      }, {
        name: '执行中',
        value: 20
      }, {
        name: '未完成',
        value: 30
      }, {
        name: '按路线完成',
        value: 30
      }, {
        name: '未按路线完成',
        value: 30
      }]
    }
  },
  components: {echarts}
}
</script>

<style lang="scss" scoped>
.itemBodys {
  width: 100%;
  position: relative;
  height: calc(100% - 0px);
}

.echartsBody {
  position: relative;
  width: 100%;
  height: calc(100% - 0px);
  display: flex;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: nowrap;
  flex-direction: row;
  align-content: flex-start;
}
</style>

echarts 组件

<template>
  <div class="echarts1">
    <div class="echarts2" ref="echarts1">

    </div>
    <div class="infos">
      <div class="num1">16515</div>
      <div class="title">任务总数</div>
    </div>
  </div>
</template>

<script>
import * as echarts from "echarts"

export default {
  name: 'echarts1',
  components: {},
  data() {
    return {}
  },
  props: {
    list: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  mounted() {
    var that = this;
    const viewElem = document.body;
    // 监听窗口变化,重绘echarts
    const resizeObserver = new ResizeObserver(() => {
      setTimeout(() => {
        that.drawEcharts()
      }, 300)
    });
    resizeObserver.observe(viewElem);
  },
  methods: {
    drawEcharts() {
      var that = this;
      let myChart = echarts.init(this.$refs.echarts1)
      var option = {
        legend: {
          height: '100%',
          show: true,
          orient: 'vertical',
          left: '5%',
          bottom: 'bottom',
          align: 'left',
          textStyle: {
            color: '#fff',
            fontSize: 14
          },
          itemWidth: 15,
          itemHeight: 10,
          itemGap: 10
        },
        series: [
          {
            type: 'pie',
            roseType: 'radius',
            center: ['62%', '50%'],
            radius: ['35%', '60%'],
            color: ['#37cbfb',
              '#eea855',
              '#4787ec',
              '#46d583',
              '#f96c5f'],
            labelLine: {
              normal: {
                length: 10
              }
            },
            label: {
              normal: {
                formatter: '{b|{b}} \n {per|{d}%} ',
                borderColor: 'transparent',
                borderRadius: 4,
                rich: {
                  b: {
                    color: 'rgba(255, 255, 255, 1)',
                    fontSize: 14
                  },
                  per: {
                    color: 'rgba(246, 246, 246, 1)',
                    fontSize: 14,
                    padding: [5, 0, 5, -5]
                  }
                },
                textStyle: {
                  color: '#fff',
                  fontSize: 14
                }
              }
            },
            data: this.list
          }
        ]
      }
      myChart.clear()
      myChart.resize()
      myChart.setOption(option)
    },
  }
}
</script>

<style lang="scss" scoped>
.echarts1 {
  position: relative;
  width: 100%;
  height: calc(100% - 0px);

  .echarts2 {
    position: relative;
    width: 100%;
    height: calc(100% - 0px);
  }

  .infos {
    position: absolute;
    width: 77.8%;
    height: 100%;
    top: 0;
    left: 22.5%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
    flex-direction: column;
    align-content: flex-start;
    pointer-events: none;

    .num1 {
      font-size: 18px;
      font-family: PingFang;
      font-weight: 500;
      color: #FFFFFF;
      padding-top: 27px;
    }

    .title {
      font-size: 14px;
      font-family: PingFang;
      font-weight: 500;
      color: #FFFFFF;
    }
  }
}
</style>

echarts 饼状图效果实例汇总

echarts 饼状图效果实例汇总

喜欢