echarts——饼图+实线阴影+虚线外边展示图

1.示例图

 2.echarts配置

option = {
  title: {
    text: '5',
    x: 'center',
    y: '30%',
    itemGap: 5,
    textStyle: {
      color: '#000',
      fontSize: 200,
    },
    subtext: 'BBU',
    subtextStyle: {
      color: '#7a7c89',
      fontSize: 80,
    },
  },
  series: [
    // 主要展示层
    {
      radius: ['55%', '65%'],
      center: ['50%', '50%'],
      type: 'pie',
      hoverAnimation: false,
      silent: true,
      itemStyle: {
        normal: {
          color: '#305cfd',
        },
      },
      labelLine: {
        show: false,
      },
      label: {
        show: false,
      },
      data: [
        {
          value: 1,
        },
      ],
    },
    // 边框的设置
    {
      radius: ['65%', '70%'],
      center: ['50%', '50%'],
      hoverAnimation: false,
      silent: true,
      type: 'pie',
      itemStyle: {
        normal: {
          color: '#e5e9f2',
        },
      },
      labelLine: {
        show: false,
      },
      label: {
        show: false,
      },
      data: [
        {
          value: 1,
        },
      ],
    },
    // 边框虚线
    {
      center: ['50%', '50%'],
      type: 'gauge',
      startAngle: 270,
      endAngle: -89.9999,
      axisTick: {
        show: false,
        length: 20,
      },
      axisLabel: {
        show: false,
      },
      radius: '91%',
      splitNumber: '150',
      axisLine: {
        show: false,
        lineStyle: {
          color: '#e6ebfe',
          width: 60,
        },
      },
      splitLine: {
        length: 10,
        lineStyle: {
          width: 10,
          color: '#e6ebfe',
        },
      },
      detail: {
        show: false,
      },
    },
  ],
};

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,你需要在 React 项目中安装 echarts: ``` npm install echarts --save ``` 然后,在需要使用饼图的组件中引入 echarts,并在组件的生命周期函数 `componentDidMount` 中初始化 echarts 实例,并使用数据渲染饼图。 例如,以下是一个简单的饼图组件的代码: ``` import React, { Component } from 'react'; import echarts from 'echarts'; class PieChart extends Component { componentDidMount() { this.initChart(); } initChart = () => { const { data } = this.props; const chart = echarts.init(this.chartRef); chart.setOption({ tooltip: { trigger: 'item', formatter: '{a} <br/>{b}: {c} ({d}%)', }, series: [ { name: '访问来源', type: 'pie', radius: ['50%', '70%'], avoidLabelOverlap: false, label: { show: false, position: 'center', }, emphasis: { label: { show: true, fontSize: '30', fontWeight: 'bold', }, }, labelLine: { show: false, }, data, }, ], }); }; render() { return ( <div ref={(ref) => { this.chartRef = ref; }} style={{ width: '100%', height: '300px' }} /> ); } } export default PieChart; ``` 在上面的代码中,我们使用 `componentDidMount` 函数初始化 echarts 实例,并使用传递进来的数据渲染饼图。注意,我们在组件的 `render` 函数中返回一个 `div` 元素,这个元素的 `ref` 属性绑定了一个回调函数,用来获取这个元素的引用,以便后续使用 echarts 来渲染表。 在父组件中,我们可以使用以下代码来渲染这个饼图组件: ``` import React, { Component } from 'react'; import PieChart from './PieChart'; class App extends Component { state = { data: [ { value: 335, name: '直接访问' }, { value: 310, name: '邮件营销' }, { value: 234, name: '联盟广告' }, { value: 135, name: '视频广告' }, { value: 1548, name: '搜索引擎' }, ], }; render() { const { data } = this.state; return ( <div> <PieChart data={data} /> </div> ); } } export default App; ``` 在父组件中,我们传递一个 `data` 属性给饼图组件,这个属性包含了用于渲染饼图的数据。最终,我们可以在页面中看到一个简单的饼图

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值