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();
  }, []);
相关推荐
耶啵奶膘32 分钟前
uniapp+firstUI——上传视频组件fui-upload-video
前端·javascript·uni-app
视频砖家1 小时前
移动端Html5播放器按钮变小的问题解决方法
前端·javascript·viewport功能
lyj1689971 小时前
vue-i18n+vscode+vue 多语言使用
前端·vue.js·vscode
小白变怪兽3 小时前
一、react18+项目初始化(vite)
前端·react.js
ai小鬼头3 小时前
AIStarter如何快速部署Stable Diffusion?**新手也能轻松上手的AI绘图
前端·后端·github
墨菲安全4 小时前
NPM组件 betsson 等窃取主机敏感信息
前端·npm·node.js·软件供应链安全·主机信息窃取·npm组件投毒
GISer_Jing4 小时前
Monorepo+Pnpm+Turborepo
前端·javascript·ecmascript
天涯学馆4 小时前
前端开发也能用 WebAssembly?这些场景超实用!
前端·javascript·面试
我在北京coding5 小时前
TypeError: Cannot read properties of undefined (reading ‘queryComponents‘)
前端·javascript·vue.js
前端开发与ui设计的老司机5 小时前
UI前端与数字孪生结合实践探索:智慧物流的货物追踪与配送优化
前端·ui