orgchart实现组织结构图

article/2025/10/6 23:35:31

之前项目需要我搞一个组织架构图,用大约一周时间挑选了框架并开发,最后用orgchart搞出来了,先上结果图

 

orgchart下载地址 :https://github.com/dabeng/OrgChart

打开下载的压缩包,如下图

然后可以打开demo目录,里面是例子,我们可以根据例子来修改成我们自己的样式,先来看一下他的基本样式

打开之后我们就可以根据他的例子来进行修改,我的组织结构图的主要代码如下:

<%--Created by IntelliJ IDEA.User: mzDate: 2018/10/18Time: 10:45To change this template use File | Settings | File Templates.
--%><%--------之前有些无关紧要的部分略过----------%><%--3-1,股权结构图的结构图部分--%><div id="chart-container"></div><%--3-2,结构图的脚本部分--%><script type="text/javascript">$(function () {var datascource = {'name': '德玛西亚','rate': '','childnum': '','className': 'motherC','children': [{'name': '子公司', 'childnum': '子公司数:2家', 'rate': '', 'className': 'childC','children': [{'name': '<br>德<br>吗<br>西<br>亚','childnum': '2家','rate': '100%','className': 'leafC','children': [{'name': '<br>德<br>吗<br>西<br>亚','childnum': '0家','rate': '100%','className': 'leafC'},{'name': '<br>德<br>吗<br>西<br>亚', 'childnum': '0家', 'rate': '100%', 'className': 'leafC'}]},{'name': '<br>德<br>吗<br>西<br>亚','childnum': '2家','rate': '100%','className': 'leafC','children': [{'name': '<br>德<br>吗<br>西<br>亚','childnum': '0家','rate': '100%','className': 'leafC'},{'name': '<br>德<br>吗<br>西<br>亚', 'childnum': '0家', 'rate': '100%', 'className': 'leafC'}]}]},{'name': '分公司', 'childnum': '分公司数:0家', 'rate': '', 'className': 'branchC'},{'name': '控股公司', 'childnum': '控股公司数:3家', 'rate': '', 'className': 'joinC','children': [{'name': '<br>李<br>润<br>石<br>风<br>投<br>1','childnum': '0家','rate': '100%','className': 'leafC'},{'name': '<br>李<br>润<br>石<br>风<br>投<br>2','childnum': '0家','rate': '100%','className': 'leafC'},{'name': '<br>李<br>润<br>石<br>风<br>投<br>3','childnum': '0家','rate': '100%','className': 'leafC'}]}]};var nodeTemplate = function (data) {var str = '';str += '<div class="name" style="color: white">'+data.name+'</div>';str += '<div class="rate" style="color: white">'+data.rate+'</div>';str += '<div class="childnum" style="color: white">'+data.childnum+'</div>';return str;<%--return '--%><%--<div class="name" >${data.name}</div> <div class="childnum">${data.childnum}</div><div class="rate">${data.rate}</div>--%><%--';--%>};var oc = $('#chart-container').orgchart({'data': datascource,'nodeTemplate': nodeTemplate,'toggleSiblingsResp': false,'direction': 'T2B',//   visibleLevel【number】:默认展开几级'visibleLevel': 3,parentNodeSymbol: null});});</script></div>

下面是官网给的一些参数,我们可以根据这些参数来修改组织架构图的样式

NameTypeRequiredDefaultDescription
datajson or stringyes datasource usded to build out structure of orgchart. It could be a json object or a string containing the URL to which the ajax request is sent.
panbooleannofalseUsers could pan the orgchart by mouse drag&drop if they enable this option.
zoombooleannofalseUsers could zoomin/zoomout the orgchart by mouse wheel if they enable this option.
zoominLimitnumberno7Users are allowed to set a zoom-in limit.
zoomoutLimitnumberno0.5Users are allowed to set a zoom-out limit.
directionstringno"t2b"The available values are t2b(implies "top to bottom", it's default value), b2t(implies "bottom to top"), l2r(implies "left to right"), r2l(implies "right to left").
verticalLevelinteger(>=2)no Users can make use of this option to align the nodes vertically from the specified level.
toggleSiblingsRespbooleannofalseOnce enable this option, users can show/hide left/right sibling nodes respectively by clicking left/right arrow.
ajaxURLjsonno It inclueds four properites -- parent, children, siblings, families(ask for parent node and siblings nodes). As their names imply, different propety provides the URL to which ajax request for different nodes is sent.
visibleLevelpositive integerno999It indicates the level that at the very beginning orgchart is expanded to.
nodeTitlestringno"name"It sets one property of datasource as text content of title section of orgchart node. In fact, users can create a simple orghcart with only nodeTitle option.
parentNodeSymbolstringno"fa-users"Using font awesome icon to imply that the node has child nodes.
nodeContentstringno It sets one property of datasource as text content of content section of orgchart node.
nodeIdstringno"id"It sets one property of datasource as unique identifier of every orgchart node.
nodeTemplatefunctionno It's a template generation function used to customize any complex internal structure of node. It recieves only one parameter: "data" stands for json datasoure which will be use to render one node.
createNodefunctionno It's a callback function used to customize every orgchart node. It recieves two parameters: "$node" stands for jquery object of single node div; "data" stands for datasource of single node.
exportButtonbooleannofalseIt enable the export button for orgchart.
exportFilenamestringno"Orgchart"It's filename when you export current orgchart as a picture.
exportFileextensionstringno"png"Available values are png and pdf.
chartClassstringno""when you wanna instantiate multiple orgcharts on one page, you should add diffent classname to them in order to distinguish them.
draggablebooleannofalseUsers can drag & drop the nodes of orgchart if they enable this option. **Note**: this feature doesn't work on IE due to its poor support for HTML5 drag & drop API.
dropCriteriafunctionno Users can construct their own criteria to limit the relationships between dragged node and drop zone. Furtherly, this function accept three arguments(draggedNode, dragZone, dropZone) and just only return boolen values.
initCompletedfunctionno It can often be useful to know when your table has fully been initialised, data loaded and rendered, particularly when using an ajax data source. It recieves one parament: "$chart" stands for jquery object of initialised chart.

 

我们最主要关注的是下面几个属性:

//传数据的,可以是json或者string
'data' : datascource,
//通过单击左/右箭头分别显示/隐藏左/右兄弟节点,
'toggleSiblingsResp': false,
//控制结构图的方向,String 默认是t2b,T2B:"从上到下",B2T:"从底到上",L2R:"左到右",R2L:"向左到右"
'direction':'T2B',
//   visibleLevel:默认展开几级
'visibleLevel':3,// 是否可以通过鼠标拖动组织架构图
// 'pan':true,
// 是否可以通过滚轮放大缩小组织架构图,以及放大缩小的比例
// 'zoom':true,
// 'zoominLimit':7
// 'zoomoutLimit':0.5
// 是否可以拖动和删除OrgChart节点
// 'draggable':true,
// 父节点的左上是否有个图标来说明有子节点parentNodeSymbol:null,
// createNode': function($node, data) 目前没用到,还不清楚用途
// nodeTemplate,目前用到的最重要的一个属性,用来自定义结点

最开始使用orgchart的时候因为他可以四个方向隐藏,所以可能有点迷,而且我的项目基本上只用得到向下隐藏,因此我在js文件中把其他三个方向的隐藏语句都注释掉了,此外我还自定义一些css以修饰组织架构图,使其符合我的要求


/*---------------------------------------------------------------------------------------------------------*/
/*----下面开始是结构图的样式-----------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------*//*这个类可以控制结构图的背景*/
.orgchart {background: #CDE6FA;height: 1000px;width: calc(100%);}/*自定义的颜色和结构,用来修饰结构图的整体颜色和大小*//*母公司------------------------------------------------------------------------------------------------------*//*设置根节点的样式*/
.orgchart .motherC{width: 195px;
}.orgchart .motherC .name {background-color: #034273;border-color: #034273;width: 195px;height: 40px;line-height: 40px;font-size: 17px;font-weight: bold;vertical-align: middle;border-radius: 4px;margin:0px auto;
}.orgchart .motherC .childnum, .orgchart .motherC .rate {width: 0px;height: 0px;margin:0px auto;
}/*子公司,控股公司,分公司三个块------------------------------------------------------------------------------*/
/*子公司-------------------------------------*/
.orgchart .childC{width: 195px;
}
.orgchart .childC .name {background-color: #f15a00;border-color: #f15a00;width: 195px;height: 37px;line-height: 37px;font-size: 17px;font-weight: bold;vertical-align: middle;text-align: center; /*水平居中*/line-height: 37px;font-size: 17px;font-weight: bold;vertical-align: middle;text-align: center; /*水平居中*/border-top-left-radius: 4px;border-top-right-radius: 4px;margin:0px auto;
}.orgchart .childC .childnum {background-color: #f15a00;border-color: #f15a00;width: 195px;height: 20px;font-size: 15px;text-align: center; /*水平居中*/border-bottom-left-radius: 4px;border-bottom-right-radius: 4px;margin:0px auto;
}.orgchart .childC .rate {background-color: #f15a00;border-color: #f15a00;width: 0px;height: 0px;margin:0px auto;
}/*分公司--------------------------------------*/
.orgchart .branchC{width: 195px;
}
.orgchart .branchC .name {background-color: #3079bf;border-color: #3079bf;width: 195px;height: 37px;line-height: 37px;font-size: 17px;font-weight: bold;vertical-align: middle;text-align: center; /*水平居中*/line-height: 37px;font-size: 17px;font-weight: bold;vertical-align: middle;text-align: center; /*水平居中*/border-top-left-radius: 4px;border-top-right-radius: 4px;margin:0px auto;
}.orgchart .branchC .childnum {background-color: #3079bf;border-color: #3079bf;width: 195px;height: 20px;font-size: 15px;text-align: center; /*水平居中*/border-bottom-left-radius: 4px;border-bottom-right-radius: 4px;margin:0px auto;
}.orgchart .branchC .rate {background-color: #3079bf;border-color: #3079bf;width: 0px;height: 0px;margin:0px auto;
}/*参股公司-------------------------------------------*/
.orgchart .joinC{width: 195px;
}.orgchart .joinC .name {background-color: #2e77be;border-color: #2e77be;width: 195px;height: 37px;line-height: 37px;font-size: 17px;font-weight: bold;vertical-align: middle;text-align: center; /*水平居中*/line-height: 37px;font-size: 17px;font-weight: bold;vertical-align: middle;text-align: center; /*水平居中*/border-top-left-radius: 4px;border-top-right-radius: 4px;margin:0px auto;
}.orgchart .joinC .childnum {background-color: #2e77be;border-color: #2e77be;width: 195px;height: 20px;font-size: 15px;text-align: center; /*水平居中*/border-bottom-left-radius: 4px;border-bottom-right-radius: 4px;margin:0px auto;
}.orgchart .joinC .rate {background-color: #2e77be;border-color: #2e77be;width: 0px;height: 0px;margin:0px auto;
}/*二级公司的叶子,也就是三级公司-----------------------------------------*/.orgchart .leafC .name {background-color: #004500;border-color: #004500;/*border-bottom-color: white;*/border-top-left-radius: 4px;border-top-right-radius: 4px;width: 41px;height: 137px;font-size: 12px;margin:0px auto;
}.orgchart .leafC .childnum {background-color: #004500;border-color: blue;border-bottom-left-radius: 4px;border-bottom-right-radius: 4px;font-size: 12px;/*border-top-color: white;*/width: 41px;height: 25px;margin:0px auto;
}.orgchart .leafC .rate {background-color: #004500;border-color: blue;/*border-top-color: white;*//*border-bottom-color: white;*/font-size: 12px;width: 41px;height: 35px;margin:0px auto;
}/*-其他关于块的配置-------------------------------------------------------------------*/.orgchart .leafC, .orgchart .joinC, .orgchart .motherC, .orgchart .childC, .orgchart .branchC {padding-top: 0px;padding-bottom: 0px;
}/*-线条的配置-目前基本没动-------------------------------------------------------------------------------*/
.orgchart .lines:nth-child(3) td {box-sizing: border-box;height: 20px;
}
.orgchart .lines .topLine {border-top: 2px solid rgba(217, 83, 79, 0.8);
}.orgchart .lines .rightLine {border-right: 1px solid rgba(217, 83, 79, 0.8);float: none;border-radius: 0;
}.orgchart .lines .leftLine {border-left: 1px solid rgba(217, 83, 79, 0.8);float: none;border-radius: 0;
}.orgchart .lines .downLine {background-color: rgba(217, 83, 79, 0.8);margin: 0 auto;height: 20px;width: 2px;float: none;
}
/*----关于按钮的配置-----------------------------------------------------------------*/

基本就这些,自己琢磨一些东西并完成还是很有成就感的

 


http://chatgpt.dhexx.cn/article/LMeotROI.shtml

相关文章

orgChart的简单使用,实现树状图结构

还不知道这个插件的小伙伴可以先去官网下载&#xff0c;orgchart官网链接 呐&#xff0c;下载下来就是这样的&#xff1a; 我们把他解压出来&#xff1a; 点进去以后&#xff0c;直接找到index.html文件用浏览器打开&#xff0c;就是这样的啦&#xff1a; 这1--24都是样式样例…

orgChart生成组织结构图应用

orgChart 是一个开源JS&#xff0c;可用于生成组织结构图。现构建如下&#xff1a; 1&#xff09;动态生成HTML作为数据source var preTitle "";var content "<ul idbasic-stacking-source classhide><li>Band<ul>"; // header$.each…

OrgChart - 配置项详解 (精选+原创)

OrgChart 使用教程 &#xff08;一&#xff09; 没用开场白… 近日来&#xff0c;公司要求做一份web组织架构图&#xff0c;正好我使用的框架是vue &#xff0c;自己写太麻烦&#xff0c;于是找一找有没有合适的组件&#xff0c;直接套用。 于是找到了 OrgChart 这个 开源的组…

orgChart实现竖向排列组织图(js实现组织机构图)

一、前言 快过年了&#xff0c;博主这几天不算忙&#xff0c;又刚好用到orgChart来做组织机构图&#xff0c;写了这篇文章&#xff0c;欢迎大家指正。注意&#xff1a;我说的竖向是指文字竖着排列。 依赖库&#xff1a;jquery&#xff0c;jquery颜色选择器&#xff0c;orgCha…

武汉python自动化测试招聘,python自动化测试工程师招聘_Python-自动化测试面试

1、以你做过的项目&#xff0c;举例来说一下你的自动化测试是怎么做的&#xff1f; 参考答案&#xff1a;就拿简历上的ecshop项目来说吧&#xff0c;在编写脚本前&#xff0c;我们会对系统进行评估&#xff0c;确认这个系统可不可以实现UI自动化&#xff0c;如果可以的话&#…

测试ai模糊软件,AE/PR人工智能自动人脸检测马赛克模糊插件

Blace – AI Face Detection是一款作用在AE以及PR软件中的AI插件&#xff0c;能够自动识别检测人脸并智能添加马赛克边框&#xff0c;易于使用且基于AI的检测&#xff0c;控制检测区域并排除检测&#xff0c;有需要的用户不要错过了&#xff0c;赶快来下载吧&#xff01; 兼容性…

自动化面试题

自动化面试题 自动化&#xff1a;将人工测试转换成自动化脚本/工具去运行 优势&#xff1a;节省时间&#xff08;20% - 30%&#xff09;&#xff0c;提高工作效率 Python selenium/appium/airtest/requests unittest Jenkins WEB自动化 1. 什么样的项目适合做自动化&…

Python&OpenCV自动人脸打马赛克&调色系统[源码&UI操作界面&部署教程]

1.视频演示&#xff1a; [项目分享]Python&#xff06;OpenCV自动人脸打马赛克&#xff06;调色系统[源码&#xff06;UI操作界面&#xff06;部署教程] 2.图片演示&#xff1a; 3.图像颜色检索&#xff06;替换&#xff1a; 4.马赛克分类&#xff1a; 使用opencv库中的haar…

Python opencv:人眼/人脸识别并实时打码处理

利用Pythonopencv实现从摄像头捕获图像&#xff0c;识别其中的人眼/人脸&#xff0c;并打上马赛克。 系统环境&#xff1a;Windows 7 Python 3.6.3 opencv 3.4.2 一、系统、资源准备 要想达成该目标&#xff0c;需要满足一下几个条件&#xff1a; 找一台带有摄像头的电脑…

seleniumxpath打码平台

selenium使用 一 bs4搜索文档树二 css选择器三 selenium基本使用四 无界面浏览器五 selenium其它用法5.1 登录百度5.2 获取位置属性大小&#xff0c;文本5.3 元素操作5.4 执行js代码5.5 切换选项卡5.6 浏览器前进后退5.7 异常处理 六 selenium登录cnblogs获取cookie七 抽屉半自…

第十一章 自动编码器

简介&#xff1a;自动编码器是一种可以进行无监督学习的神经网络模型。一般而言&#xff0c;一个完整的自动编码器主要由两部分组成&#xff0c;分别是用于核心特征提取的编码部分和可以实现数据重构的解码部分。 1.自动编码器入门 在自动编码器中负责编码的部分也叫做编码器&a…

Python 题库自动化面试题

1、自动化代码中,用到了哪些设计模式? 单例设计模式 工厂模式 PO设计模式 数据驱动模式 面向接口编程设计模式 2、什么是断言( Assert) ? 断言 Assert 用于在代码中验证实际结果是不是符合预期结果&#xff0c; 如果测试用例执行失败会抛出异常并提供断言日志 3、什么…

Python实现对视频自动打码

我们在观看视频的时候&#xff0c;有时候会出现一些奇怪的马赛克&#xff0c;影响我们的观影体验&#xff0c;那么这些马赛克是如何精确的加上去的呢&#xff1f; 本次我们就来用Python实现对视频自动打码&#xff01; 准备工作 环境咱们还是使用 Python3.8 和 pycharm2021 即…

Python——超级鹰打码平台实现selenium对b站的自动化登陆

目录 一 、Chrome&#xff08;谷歌&#xff09;驱动器的下载 &#xff08;一&#xff09;驱动器版本选择 &#xff08;二&#xff09;下载Chrome驱动器 二、需要安装的库 &#xff08;一&#xff09;安装命令 &#xff08;二&#xff09;指定selenium版本原因 三、实现步…

selenium 自动化测试

Selenium 是一个用于Web应用程序测试的工具&#xff0c;支持多平台、多浏览器、多语言去实现自动化测试。目前在Web自动化领域应用越来越广泛。 selenium 介绍 Selenium的特点如下&#xff1a; 开源、免费多浏览器支持&#xff1a;Firefox、Chrome、IE、Opera、Edge多平台支…

深度学习中的自动编码器:TensorFlow示例

什么是自动编码器? 自动编码器是重建输入的绝佳工具。简单来说,机器就是一个图像,可以生成一个密切相关的图片。这种神经网络中的输入是未标记的,这意味着网络能够在没有监督的情况下进行学习。更准确地说,输入由网络编码,仅关注最关键的特征。这是自动编码器因降维而流行…

博客论坛自动采集器 - 蓝天采集器源码

介绍&#xff1a; 博客论坛自动采集器 做一个自动采集文章的网站&#xff0c;在你网站根目录创建一个目录随便我这边是caiji&#xff0c;然后把采集器的源码上传到caiji里面去。 安装:你的域名/caiji访问配置好数据库什么的安装就行。数据前缀不要和原来博客的相同。 安装完成…

Pytorch基础-07-自动编码器

自动编码器&#xff08;AutoEncoder&#xff09;是一种可以进行无监督学习的神经网络模型。一般而言&#xff0c;一个完整的自动编码器主要由两部分组成&#xff0c;分别是用于核心特征提取的编码部分和可以实现数据重构的解码部分。 1 自动编码器入门 在自动编码器中负责编码…

python手工打码_python云打码

广告关闭 腾讯云11.11云上盛惠 &#xff0c;精选热门产品助力上云&#xff0c;云服务器首年88元起&#xff0c;买的越多返的越多&#xff0c;最高返5000元&#xff01; 为什么需要了解打码平台的使用现在很多网站都会使用验证码来进行反爬&#xff0c;所以为了能够更好的获取…

python你实现视频自动打码,了解妨碍你观看精彩的马赛克是怎么精准形成的

前言 嗨喽&#xff01;大家好呀&#xff0c;这里是魔王呐~ 我们在观看视频的时候&#xff0c;总有一些精准得马赛克挡住我们想看得地方&#xff0c;严重影响我们的观影体验&#xff01;&#xff01; 那么这些马赛克是如何精确的加上去的呢&#xff1f; 本次我们就来用Python…