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()
相关推荐
parade岁月16 分钟前
VTable Guild 3.0.0 发布,面向 Vue 3 的 ProTable 式业务表格
前端
xurileidian33 分钟前
第 17 篇 · 边玩边学Python · for 遍历 enumerate 与 zip
java·前端·python
掘金安东尼1 小时前
更多审查智能体,更少盲区:GitHub Copilot 代码审查是怎么做的
前端·github copilot
Hilaku4 小时前
2026 年了,jQuery 真的该死了吗?
前端·javascript·程序员
zach4 小时前
吃透 React setState 同步异步之谜:从批量更新、事件循环到版本演进的完整拆解
前端·react.js
不服老的小黑哥4 小时前
02-从 pnpm dev 到 Spring Boot 启动:后端服务到底怎么跑起来?
前端
htzyl2064 小时前
javaScript——this 的四种绑定:为什么箭头函数改不了它
前端·javascript
bai2734 小时前
*.js 匹配到了 B.JS:fs.globSync 在 Windows 上的五个默认值
javascript·后端
欧雷殿4 小时前
做自己的第一位客户:一人公司的数据治理公开实践
前端·ai编程·团队管理
时间的情敌5 小时前
Three.js 工业场景性能优化合集|大批量管线、InstancedMesh 实例化、合并 Geometry、显存释放
开发语言·javascript·性能优化·three.js