前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >饼状图

饼状图

作者头像
onety码生
发布2020-09-16 11:20:27
2K0
发布2020-09-16 11:20:27
举报
文章被收录于专栏:码生码生
代码语言:javascript
复制
const chart = echarts.init(canvas, null, {
      width: width,
      height: height,
      devicePixelRatio: dpr // 像素
    });
    canvas.setChart(chart);
    /* 定制每个角的label */
    const label = {
      /* 格式化 c: value, b: name */
      formatter: [
        '{value|{c}元}',
        '{name|{b}}',
      ].join('\n'),
      /* 定制CSS,可以在 formatter 中应用 */
      rich: {
        value: {
          lineHeight: 25,
          fontSize: 14,
          color: '#333333',
          align: 'center'
        },
        name: {
          fontSize: 12,
          color: '#333333',
          align: 'center',
        }
      }
    };
    let option = {
      backgroundColor: "#ffffff",
      color: ["#00B8B0", "#FF7C7C", "#0C98E7"],
      series: [
        {
          selectedMode: 'single',
          /* 选中的时候往外扩充的宽度 */
          hoverOffset: 20,
          /* 选中的时候往外扩充的宽度,会直接移动 */
          selectedOffset: 0,
          /* 顺时加载 */
          clockWise: true,
          avoidLabelOverlap: true,
          type: 'pie',
          /* 中心点的 x,y */
          center: ['50%', '50%'],
          /* 半径 */
          radius: ['30%', '45%'],
          /* label 线条 */
          labelLine: {
            /* 正常下 */
            normal: {
              show: true,
              length: 5,
              length2: 25
            },
            /* 高亮下 */
            emphasis: {
              show: true
            }
          },
          position: 'outer',
          data: [{
            value: 12759,
            name: '交强险',
            label,
          }, {
            value: 12759,
            name: '车价',
            label,
          }, {
            value: 20000,
            name: '商业保险',
            label
          }]
        }
      ]
    };
    /* 更新配置 */
    chart.setOption(option);
    /* 默认选中 */
    chart.dispatchAction({
      type: 'highlight',
      seriesIndex: 0,
      dataIndex: 0
    });
    this.eChart = chart;
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档