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()
相关推荐
清沫几秒前
规训 AI Agent 实践
前端·ai编程·cursor
明仔的阳光午后1 小时前
React 入门 02:从单页面应用到多页面应用
前端·react.js·前端框架
.生产的驴1 小时前
React 页面路由ReactRouter 路由跳转 参数传递 路由配置 嵌套路由
前端·javascript·react.js·前端框架·json·ecmascript·html5
非凡ghost1 小时前
批量转双层PDF(可识别各种语言) 中文绿色版
前端·windows·pdf·计算机外设·软件需求
苏卫苏卫苏卫1 小时前
【码源】智能无人仓库管理系统(详细码源下~基于React+TypeScript+Vite):
前端·react.js·typescript·vite·项目设计·智能无人仓库管理系统·码源
打小就很皮...1 小时前
PDF 下载弹窗 content 区域可行性方案
前端·javascript·pdf
Felicity_Gao4 小时前
uni-app VOD 与 COS 选型、开发笔记
前端·笔记·uni-app
我狸才不是赔钱货5 小时前
前端技术栈全景图:从HTML到现代框架的演进之路
前端·html
百花~6 小时前
前端三剑客之一 HTML~
前端·html
lang201509287 小时前
Spring远程调用与Web服务全解析
java·前端·spring