react tsx EchartsLiquidfill 组件

1.安装

 "echarts": "^5.4.2",
 "echarts-liquidfill": "^3.1.0",

2.组件

import React, { useEffect } from 'react';
import * as echarts from 'echarts';
import 'echarts-liquidfill';

const EchartsLiquidfill = (props: any) => {
   
    useEffect(() => {
        const value = 11.2
        let percent = 0.5;
       
       
        const chart = echarts.init(document.getElementById('liquidfill-chart')!);
        const font_Size = 14;//字体大小
        const option = {
            series: [{
                type: 'liquidFill',
                radius: '100%',
                with: '206px',
                data: [{
                    value: value,
                    direction: 'left',
                    itemStyle: {
                        normal: {
                            color: {
                                type: 'linear',
                                x: 0,
                                y: 0,
                                x2: 0,
                                y2: 1,
                                colorStops: [
                                    { offset: 0, color: '#238F7A' },
                                    { offset: 1, color: 'rgba(0, 0, 0, 1)' }
                                ],
                                globalCoord: false
                            },
                            borderColor: {
                                type: 'linear',
                                x: 0,
                                y: 0,
                                x2: 0,
                                y2: 1,
                                colorStops: [
                                    { offset: 0, color: '#FFDC00' },
                                    { offset: 1, color: '#AA05C4' }
                                ],
                                globalCoord: false
                            },
                            borderWidth: 10 // 设置边框宽度
                        }
                    }
                }, {
                    value: percent,
                    direction: 'right',
                    itemStyle: {
                        normal: {
                            color: {
                                type: 'linear',
                                x: 0,
                                y: 0,
                                x2: 0,
                                y2: 1,
                                colorStops: [
                                    { offset: 0, color: 'rgba(255, 220, 0, 1)' },
                                    { offset: 1, color: 'rgba(170, 5, 196, 1)' }
                                ],
                                globalCoord: false
                            }
                        }
                    }
                }],
                backgroundStyle: {
                    type: 'rgba',
                    color: [0, 0, 0, 1]
                },
                center: ['50%', '50%'],
                label: {
                    show: true,
                    position: 'inside',
                    formatter: function (params: any) {
                        return params.value.toString();
                    },
                    fontSize: font_Size
                },
                outline: {
                    show: false
                }
            }],

        };
        chart.setOption(option);
        return () => {
            chart.dispose();
        };
    }, []);


    return <div id="liquidfill-chart" ></div>;
};

export default EchartsLiquidfill;

3页面

import EchartsLiquidfill from './hooks/useEchartsLiquidfill';


<EchartsLiquidfill ></EchartsLiquidfill>




css

#liquidfill-chart {
    width: 100%;
    height: 196px;
    overflow: visible;
    margin-bottom: 20px;
    z-index: 1;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值