react用ECharts实现组织架构图

找到ECharts中路径图。

然后开始爆改。

html 复制代码
<div id={'org-' + name} style={{ width: '100%', height: 650, display: 'flex', justifyContent: 'center' }}></div>
TypeScript 复制代码
// data的数据格式
interface ChartData {
  name: string;
  value: number;
  children: ChartData[];
}
TypeScript 复制代码
const treeDepth = useRef(0);  
const initChart = () => {
    const demoId = document.getElementById('org-' + name);
    let myChart = echarts.getInstanceByDom(demoId);
    if (!myChart) {
      myChart = echarts.init(demoId);
      const options = {
        tooltip: {
          trigger: 'item',
          triggerOn: 'mousemove',
          formatter: function (params: any) {
            // 获取当前节点的所有父级名称
            const parentNames = params.treeAncestors.map((node: any, index: number) =>                 (index > 0 ? node.name : null)).filter((item: string) => item);
            // 返回父级名称,不包含值
            return parentNames.join('<br/> ');
          },
        },
        series: [
          {
            type: 'tree',
            id: 0,
            name: '工厂模型',
            layout: 'orthogonal', // 水平
            orient: 'TB', // 从上到下
            data,
            top: '10%',
            left: '8%',
            bottom: '22%',
            right: '20%',
            edgeShape: 'polyline',
            edgeForkPosition: '63%',
            initialTreeDepth: treeDepth.current,
            lineStyle: {
              // 每个节点所对应的文本标签的样式
              width: 4,
              color: '#40a9ff',
            },
            label: {
              // 每个节点所对应的文本标签的样式
              backgroundColor: '#096dd9',
              verticalAlign: 'middle',
              align: 'center',
              fontSize: 22,
              padding: [10, 10, 5, 10],
              color: '#fff',
            },
            leaves: {
              // 叶子节点的特殊配置
              label: {
                verticalAlign: 'middle',
                align: 'center',
              },
            },
            emphasis: {
              focus: 'descendant',
            },
            expandAndCollapse: true,
            animationDuration: 550,
            animationDurationUpdate: 750,
          },
        ],
      };
      myChart.setOption(options, true);
    }
  };


  useEffect(() => {
    initChart();
  }, []);
相关推荐
掘金者阿豪1 小时前
把业务数据变成共享仪表盘:Metabase可视化与远程访问实践
前端·后端
kyriewen1 小时前
折腾了半年 AI 编程工作流,最后发现效率瓶颈是桌上那块屏幕
前端·javascript·ai编程
蜗牛前端2 小时前
codex 全流程开发上线的高颜值礼簿小程序
前端·微信小程序
大龄秃头程序员2 小时前
我在图文流 App 里落地双层缓存、弱网降级与 OOM 治理
前端
老王以为2 小时前
React Renderer 分离的多平台架构
前端·react native·react.js
hunterandroid2 小时前
Kotlin Coroutines 与 Flow:让异步任务更清晰
前端
Bigger3 小时前
从零搭建 AI 代码审查服务:一份前端也能看懂的 Python 学习笔记
前端·ci/cd·ai编程
lichenyang4533 小时前
JSAPI、NAPI、Biz、Imp:ASCF Demo 如何真正调用系统能力和 C++ 能力
前端
lichenyang4534 小时前
IPC、JSVM、UIThread、libuv:ASCF 架构图里最容易混的几个词
前端
用户059540174464 小时前
Redis记忆存储故障恢复测试踩坑实录:手动测试让我漏掉了2个一致性Bug
前端·css