首页 > 其他分享 >echarts饼图实现圆环图例修改

echarts饼图实现圆环图例修改

时间:2023-04-28 15:46:00浏览次数:27  
标签:name 16 color text 图例 res data echarts 圆环

实现效果:

代码:

const option = {
  // 环形图中间文字
  title: {
    text: '1200',
    subtext: '总户数',
    textStyle: {
      fontSize: 16,
      color: '#333',
      fontWeight: 600,
    },
    subtextStyle: {
      fontSize: 12,
      color: '#333',
      fontWeight: 400,
    },
    textAlign: 'center', // 图例文字居中显示
    x: '23%', // 距离左边的距离
    y: '37%', // 距离上边的距离
  },
  legend: {
    orient: 'vertical',
    right: '10%',
    // top: 'center',
    top: '8%',
    icon: 'circle',
    // itemGap: 15, // 图例间距
    itemWidth: 10,
    data: ['正常液位时间', '超警戒时间', '异常时间'],
    textStyle: {
      fontSize: 14,
      color: '#333',
      lineHeight: 30,
      rich: {
        a: {
          color: '#4178fd',
          fontSize: 16,
          fontWeight: 600,
          lineHeight: 0, // 这里是实现图例小圆点对齐上方一行的关键
          padding: [16, 0, 0, 0], // 设置和上一行之间的间距 [上 右 下 左]
        },
        b: {
          color: '#00ce98',
          fontSize: 16,
          fontWeight: 600,
          lineHeight: 0,
          padding: [16, 0, 0, 0],
        },
        c: {
          color: '#fec856',
          fontSize: 16,
          fontWeight: 600,
          lineHeight: 0,
          padding: [16, 0, 0, 0],
        },
      },
    },
    formatter: (name) => {
      let data: string = '';

      if (name === '正常液位时间') {
        data = (Number(res.data[`${key}safe`]) * 100).toFixed();
        const text = `30户 | ${data}%`;
        return `${name}\n{a|${text}}`;
      }
      if (name === '超警戒时间') {
        data = (Number(res.data[`${key}warn`]) * 100).toFixed();
        const text = `110户 | ${data}%`;
        return `${name}\n{b|${text}}`;
      }
      if (name === '异常时间') {
        data = (Number(res.data[`${key}unknown`]) * 100).toFixed();
        const text = `50户 | ${data}%`;
        return `${name}\n{c|${text}}`;
      }
    },
  },
  series: [
    {
      name: '时间占比',
      type: 'pie',
      radius: ['43%', '58%'],
      center: ['25%', '48%'], // 左边的距离,上边的距离
      color: ['#4178fd', '#00ce98', '#fec856'],
      data: [
        {
          value: Number(res.data[key + 'safe']),
          name: '正常液位时间',
          label: {
            show: false,
          },
        },
        {
          value: Number(res.data[key + 'warn']),
          name: '超警戒时间',
          label: {
            show: false,
          },
        },
        {
          value: Number(res.data[key + 'unknown']),
          name: '异常时间',
          label: {
            show: false,
          },
        },
      ],
      emphasis: {
        itemStyle: {
          shadowBlur: 10,
          shadowOffsetX: 0,
          shadowColor: 'rgba(0, 0, 0, 0.5)',
        },
      },
    },
  ],
};

标签:name,16,color,text,图例,res,data,echarts,圆环
From: https://www.cnblogs.com/ZerlinM/p/17362370.html

相关文章

  • echarts折线实心圆点、折线阴影
    echarts作为我们前端小伙伴常用的可视化库,那我们画出有阴影的折线图,让折线图比较立体感。可以使用折线图的lineStyle实现效果如图代码如下:series:[{data:[150,230,224,218,135,147,260],type:"line",smooth:true,symbol:'circle',//将小......
  • 辽宁省 Echarts 图
    <!DOCTYPEhtml><html><head><metacharset="utf-8"><title>辽宁省地图</title><scriptsrc="https://cdn.bootcdn.net/ajax/libs/echarts/5.2.2/echarts.min.js"></script><scriptsrc=&q......
  • highchart 柱状图不要x轴,y轴,图例只要保留图
    光秃秃的柱状图前几天有个需要,做个迷你小柱状图,不要x轴、y轴、图例等等就一个光秃秃的柱状图,就是这个样子(随手截图画的,将就看吧),直接上代码。 letreport={chart:{type:'column'},title:{tex......
  • Echarts4.0 迁徙图模拟Echarts2.0样式
     由于公司业务需求做Echarts4.0的迁徙图,但是Echarts4.0默认的迁徙图的飞行轨迹和迁徙线的颜色都是一样的,比较单调,现在模拟Echarts2.0的样式模拟了一个demo,虽然没有全部相同,但大体相近。备忘一下letminigrateChart=echarts.init(document.getElementById("MinigrateChart"));......
  • vue项目中引入echarts中国地图
     最近项目中根据项目需求,展示中国地图一、下载echarts插件(我这里使用的是 4.9.0 版本)[email protected]二、在需要使用的页面引入echarts(这里是单独封装了地图组件) components/map.vue<template><divclass="map-view"><divid="main"></d......
  • Echarts
    官网:https://echarts.apache.org/examples/zh/index.html#chart-type-bar1、Echarts中饼图的使用(附:formatter中{d}百分比位数修改) 例如:label:{position:'inside',formatter:"{b}:{c}({d}%)"},效果: 参考文献:https://blog......
  • echarts treemap当份额太小时文字显示不全,解决为垂直显示全部文字
    before:after:解决: ......
  • echarts 数据密集,如果设置sampling: 'average' 会导致提示框(tooltip)无法正常显示,但是
    如果数据比较密集,设置sampling:'average'确实可以加速绘图,但同时也可能导致提示框无法正常显示的问题。这个问题的原因是,sampling会对数据进行抽样,因此不会显示原始的数据点,而是将数据点以一定规律进行采样,取平均值或最大或其他值,因此提示框的内容可能不准确。不过,有一个简单的......
  • 【前端可视化】ECharts中国地图+散点图demo
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"/><metahttp-equiv="X-UA-Compatible"content="IE=edge"/><metaname="viewport"content="w......
  • echarts 更改背景
    遇到一个问题很有意思记录一下:需求如下:使用echarts的树形图结构,更改背景颜色为环形透明状,具体图形如下思路:使用echarts提供的color更改背景颜色结果:发现此属性不生效,暂未找到原因使用backgroundColor更改渐变色背景结果:该属性不支持渐变色修改直接......