Vue3+Echarts+饼图环形图

记得给容器宽高

html 复制代码
<div id="leftChartguawang" style="height: 28vh"></div>

配置函数

javascript 复制代码
const leftChartguawang = () => {
  const chartBox = echarts.init(document.getElementById('leftChartguawang'))
  let datas = [
    [
      { name: '居民节能建筑', value: 20 },
      { name: '居民非节能建筑', value: 20 },
      { name: '非居民节能建筑', value: 30 },
      { name: '非居民非节能建筑', value: 30 }
    ]
  ]
  const option = {
    title: {
      text: '挂网总面积\n \n422.61(万㎡)',
      left: 'center',
      top: '40%',
      textStyle: {
        color: '#999',
        fontWeight: 'normal',
        fontSize: 14
      }
    },
    series: datas.map(function (data, idx) {
      var top = idx * 50
      return {
        type: 'pie',
        radius: [60, 100],
        top: top + '%',
        height: '100%',
        left: 'center',
        width: 500,
        itemStyle: {
          borderColor: '#fff',
          borderWidth: 1
        },
        label: {
          alignTo: 'edge',
          formatter: '{name|{b}}\n{time|{c} %}',
          minMargin: 5,
          edgeDistance: 10,
          lineHeight: 15,
          rich: {
            time: {
              fontSize: 10,
              color: '#999'
            }
          }
        },
        labelLine: {
          length: 15,
          length2: 0,
          maxSurfaceAngle: 80
        },
        labelLayout: function (params: any) {
          const isLeft = params.labelRect.x < chartBox.getWidth() / 2
          const points = params.labelLinePoints
          points[2][0] = isLeft ? params.labelRect.x : params.labelRect.x + params.labelRect.width
          return {
            labelLinePoints: points
          }
        },
        data: data
      }
    })
  }
  option && chartBox.setOption(option)
  window.addEventListener('resize', function () {
    chartBox.resize()
  })
}

leftChartguawang()
相关推荐
YaHuiLiang2 分钟前
小微互联网公司与互联网创业公司 -- 学历之殇
前端·后端·面试
用户26124583401615 分钟前
vue学习路线(11.watch对比computed)
前端·vue.js
CAD老兵11 分钟前
前端 Source Map 原理与结构详解
前端
gnip15 分钟前
markdown预览自定义扩展实现
前端·javascript
大猫会长26 分钟前
mac中创建 .command 文件,执行node服务
前端·chrome
旧时光_26 分钟前
Zustand 状态管理库完全指南 - 进阶篇
前端·react.js
snakeshe101028 分钟前
深入理解useState:批量更新与非函数参数支持
前端
windliang28 分钟前
Cursor 排查 eslint 问题全过程记录
前端·cursor
boleixiongdi29 分钟前
# Bsin-App Uni:面向未来的跨端开发框架深度解析
前端
G等你下课32 分钟前
AJAX请求跨域问题
前端·javascript·http