• 【金融大屏项目】—— Echarts 极坐标和柱状图实现圆角环形图(polar)


    ProgressCircleChart组件代码:

    import React, { PureComponent } from 'react';
    import echarts from 'echarts/lib/echarts';
    import 'echarts/lib/chart/pie';
    import 'echarts/lib/chart/bar';
    import 'echarts/lib/component/tooltip';
    import 'echarts/lib/component/title';
    import 'echarts/lib/component/polar';
    import styles from './index.less';
    
    class ProgressCircleChart extends PureComponent {
      constructor(props) {
        super(props);
        this.state = {};
      }
    
      componentDidMount() {
        const { data } = this.props;
        this.initProgressCircleChart(data);
        // 窗口改变重新加装定时器并重绘echarts
        window.addEventListener('resize', () => {
          this.initProgressCircleChart(data);
        });
      }
    
      componentDidUpdate() {
        const { data } = this.props;
        // 数据改变重绘echarts
        this.initProgressCircleChart(data);
        // 窗口改变重新加装定时器并重绘echarts
        window.addEventListener('resize', () => {
          this.initProgressCircleChart(data);
        });
      }
    
      initProgressCircleChart = (data) => {
        if (data.length > 0) {
          const { id, radius, center, color } = this.props;
          const myChart = echarts.init(document.getElementById(id));
          const option = {
            color: color,
            // tooltip: {
            //   trigger: 'item'
            // },
            grid: {
              left: 0,
              right: 0,
              top: 0,
              bottom: 0,
              containLabel: true
            },
            angleAxis: {
              max: data[1], // 总数
              clockwise: false, // 逆时针
              // 隐藏刻度线
              axisLine: {
                show: false
              },
              axisTick: {
                show: false
              },
              axisLabel: {
                show: false
              },
              splitLine: {
                show: false
              }
            },
            radiusAxis: {
              type: 'category',
              // 隐藏刻度线
              axisLine: {
                show: false
              },
              axisTick: {
                show: false
              },
              axisLabel: {
                show: false
              },
              splitLine: {
                show: false
              }
            },
            polar: {
              center: center,
              radius: radius //图形大小
            },
            series: [
              // {
              //   name: '',
              //   type: 'pie',
              //   radius: radius,
              //   center: center,
              //   avoidLabelOverlap: true,
              //   hoverAnimation:false, //悬停不放大突出
              //   labelLine: {
              //     normal: {
              //       show: false
              //     }
              //   },
              //   // minAngle: 15,//最小角度
              //   startAngle:230, //起始角度
              //   data: data
              // }
              {
                type: 'bar',
                data: [{
                  name: '',
                  value: data[0],
                  itemStyle: {
                    normal: {
                      color: color[0]
                    },
                  }
                }],
                coordinateSystem: 'polar',
                roundCap: true,
                barWidth: 8,
                barGap: '-100%', // 两环重叠
                z: 2,
              },{ // 灰色环
                type: 'bar',
                data: [{
                  value: data[1],
                  itemStyle: {
                    color: color[1]
                  }
                }],
                coordinateSystem: 'polar',
                roundCap: true,
                barWidth: 8,
                barGap: '-100%', // 两环重叠
                z: 1
              }
            ]
          };
          if(id==='zncChart' || id === 'zcpuChart' || id === 'zcpChart' || id === 'zyxhChart'){
            option.title = {
              show:true,
              text: data[0],
              textAlign:'center',
              x:'45%',
              // y: 22,
              y: '23.91%',
              itemGap: 4,//主副标题纵向间隔,单位px,默认为10
              textStyle: {
                fontSize: 22,
                fontWeight: 400,
                color: '#0AC3E5'
              },
              subtextStyle:{
                fontSize: 16,
                fontWeight: 400,
                color: '#ffffff'
              }
            }
          }
          if(id==='zncChart' || id === 'zcpChart' || id === 'zyxhChart'){
            option.title.subtext = 'TB';
          }
          if(id === 'zcpuChart'){
            option.title.subtext = '核';
          }
          myChart.setOption(option);
        }
      };
    
      render() {
        const { data, id, width, height } = this.props;
        return (
          <div className={styles.contain}>
            <div className={styles.chart} id={id} style={{ width, height }} />
          </div>
        );
      }
    }
    
    export default ProgressCircleChart;
    
    ProgressCircleChart.defaultProps = {
      id: 'progressCircleChart',
       '100%',
      height: '100%',
      // radius: [19.5, 33.5],
      radius: ['56.62%', '97.1%'],
      center: ['50%', '50%'],
      color: ['#BF00FE', 'rgba(64,0,208, 0.6)'],
      data: [ 80, 100]
    };
    

    less代码:

    .contain {
      display: flex;
      align-items: center;
       100%;
      height: 100%;
    
      .chart {
         100%;
        height: 100%;
      }
    }
    

    引用组件代码:

    <ProgressCircleChart id='zncChart' color={zncColor} radius={middleProgressRadius} data={zncData}/>
    

    官方 Pull requests https://github.com/apache/incubator-echarts/pull/11393


    注:转载请注明出处 

  • 相关阅读:
    c#正则表达式应用实例
    C# 中堆栈,堆,值类型,引用类型的理解 (摘抄)
    c#用正则表达式获得指定开始和结束字符串中间的一段文本
    asp.net c#截取指定字符串函数
    <收藏>提高Web性能的14条法则(详细版)
    利用Anthem.net 实现前台javascript调用服务器端c#函数 及流程分析
    Anthem.net
    jQuery animate(滑块滑动)
    .NET使用母版页后,控件名称自动生成导致js无法正常操作.net控件的问题
    Cocos2dx跨平台Android环境配置
  • 原文地址:https://www.cnblogs.com/ljq66/p/15918575.html
Copyright © 2020-2023  润新知