echars 树形图

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

const ThreeProgress = ({ deviceInfo }) => { // 此名称用来生成用例名称,可进行语义化命名
    const chartRef = useRef(null);

    const option = {
        // 标题
        title: {
            text: `设备总数 \n ${deviceInfo.totalNumberOfDevices || 0}`,
            left: '95px',
            top: '80px',
            textAlign: 'center',
            textStyle: {
                fontSize: 14
            }
        },
        // 提示信息
        tooltip: {
            trigger: 'item',
            position: 'inside',
            confine: true
        },
        // 图例
        legend: {
            orient: 'vertical',
            right: 0,
            top: 'center',
            icon: 'circle', 
        },
        grid: { left: '5', top: '15', right: '0', bottom: '15' },
        series: [
            {
                name: '设备信息',
                type: 'pie',
                radius: ['45%', '55%'], // 外半径和内半径
                center: ['100px', '50%'],
                label: {
                    show: false
                },
                labelLine: {
                    show: false
                },
                data: [
                    { value: deviceInfo.cloudDevices || 0, name: `已上云设备 \u0020 \u0020 \u0020 \u0020  ${deviceInfo.cloudDevices || 0}(${deviceInfo.totalNumberOfDevices ? ((parseInt(deviceInfo.cloudDevices)/parseInt(deviceInfo.totalNumberOfDevices))*100).toFixed(1): '0.0'}%)` },
                    { value: deviceInfo.notCloudDevices || 0, name: `未上云设备 \u0020 \u0020 \u0020 \u0020  ${deviceInfo.notCloudDevices || 0}(${deviceInfo.totalNumberOfDevices ? ((parseInt(deviceInfo.notCloudDevices)/parseInt(deviceInfo.totalNumberOfDevices))*100).toFixed(1) : '0.0'}%)` }
                ]
            },
            {
                name: '设备信息',
                type: 'pie',
                radius: ['65%', '75%'], // 外半径和内半径
                center: ['100px', '50%'],
                label: {
                    show: false
                },
                labelLine: {
                    show: false
                },
                data: [
                    { value: deviceInfo.intoManagement || 0, name: `已纳入4A管理 \u0020 \u0020  ${deviceInfo.intoManagement || 0}(${deviceInfo.totalNumberOfDevices ? ((parseInt(deviceInfo.intoManagement)/parseInt(deviceInfo.totalNumberOfDevices))*100).toFixed(1) : '0.0'}%)` },
                    { value: deviceInfo.notIntoManagement || 0, name: `未纳入4A管理 \u0020 \u0020  ${deviceInfo.notIntoManagement || 0}(${deviceInfo.totalNumberOfDevices ? ((parseInt(deviceInfo.notIntoManagement)/parseInt(deviceInfo.totalNumberOfDevices))*100).toFixed(1) : '0.0'}%)` }
                ]
            },
            {
                name: '设备信息',
                type: 'pie',
                radius: ['85%', '95%'], // 外半径和内半径
                center: ['100px', '50%'],
                label: {
                    show: false
                },
                labelLine: {
                    show: false
                },
                data: [
                    { value: deviceInfo.devicesMonitored || 0, name: `已监控设备 \u0020 \u0020 \u0020 \u0020  ${deviceInfo.devicesMonitored || 0}(${deviceInfo.totalNumberOfDevices ? ((parseInt(deviceInfo.devicesMonitored)/parseInt(deviceInfo.totalNumberOfDevices))*100).toFixed(1) : '0.0'}%)` },
                    { value: deviceInfo.notDevicesMonitored || 0, name: `未监控设备 \u0020 \u0020 \u0020 \u0020  ${deviceInfo.notDevicesMonitored || 0}(${deviceInfo.totalNumberOfDevices ? ((parseInt(deviceInfo.notDevicesMonitored)/parseInt(deviceInfo.totalNumberOfDevices))*100).toFixed(1) : '0.0'}%)` }
                ]
            }
        ]
    };
    useEffect(() => {
        const chart = echarts.init(chartRef.current);
        chart.setOption(option);
        return () => {
            chart.dispose(); // 清理chart实例
        };
    }, [deviceInfo]);

    return (
        <div ref={chartRef} style={{ width: '410px', height: '192px'}}>

        </div>

    );
};

export default ThreeProgress;

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值