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()
相关推荐
2601_949480063 小时前
【无标题】
开发语言·前端·javascript
css趣多多3 小时前
Vue过滤器
前端·javascript·vue.js
理人综艺好会3 小时前
Web学习之用户认证
前端·学习
●VON4 小时前
React Native for OpenHarmony:项目目录结构与跨平台构建流程详解
javascript·学习·react native·react.js·架构·跨平台·von
We་ct4 小时前
LeetCode 36. 有效的数独:Set实现哈希表最优解
前端·算法·leetcode·typescript·散列表
爱吃大芒果4 小时前
Flutter for OpenHarmony 实战:mango_shop 路由系统的配置与页面跳转逻辑
开发语言·javascript·flutter
qq_177767374 小时前
React Native鸿蒙跨平台实现消息列表用于存储所有消息数据,筛选状态用于控制消息筛选结果
javascript·react native·react.js·ecmascript·harmonyos
weixin_395448914 小时前
main.c_cursor_0129
前端·网络·算法
沐雪架构师4 小时前
LangChain 1.0 Agent开发实战指南
开发语言·javascript·langchain
2501_940007894 小时前
Flutter for OpenHarmony三国杀攻略App实战 - 战绩记录功能实现
开发语言·javascript·flutter