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()
相关推荐
小江的记录本4 小时前
【CSS】CSS 动画:transition、animation、transform、CSS3 新特性(附《思维导图》)
前端·css·安全·spring·前端框架·css3·动画
circuitsosk5 小时前
任务规划器的三种范式对比:ReAct、Plan-and-Execute 与 Tree-of-Thought 在真实业务中的取舍
前端·javascript·python·react.js·llm·ai agent
hzxpaipai6 小时前
企业官网技术架构拆解:前端、后台、数据库、服务器如何协同
前端·数据库·架构
小磊哥er6 小时前
深入解构Claude Code - 第 12 篇 · 整体串起来
javascript·ai编程
小磊哥er6 小时前
深入解构Claude Code - 第 11 篇 · 工程上的讲究
javascript·ai编程
深念Y8 小时前
Lenovo XiaoXinAir 14 — 性能模式切换
前端·网络
计算机魔术师8 小时前
Meta突然杀进第一梯队:一个新模型,把AI推理成本打下来8倍
前端
IT_陈寒8 小时前
Redis缓存雪崩把我坑惨了,这次长记性了
前端·人工智能·后端
风骏时光牛马9 小时前
提示词工程:大模型效能挖掘与指令设计实战
前端