orgChart 是一个开源JS,可用于生成组织结构图。现构建如下:
1)动态生成HTML作为数据source
- var preTitle = "";
- var content = "<ul id='basic-stacking-source' class='hide'><li>Band<ul>"; // header
-
- $.each(titleNameList, function(i, item){
- if (preTitle != item.title) {
- if (preTitle != "") {
- content += "</ul></li>"; // end name & title
- }
- preTitle = item.title;
- content += "<li>" + item.title + "<ul>";
-
- }
- content += "<li>" + item.name + "</li>";
- });
- content += "</ul></li>"; // end name & title finally
- content += "</ul></li></ul>"; // end header
- $("#temp").html(content);
2)调用orgChart
- $("#basic-stacking-source").orgChart({
- container: $("#names_chart")
- });
记得引入相应的包
- jquery.orgchart.css
- /echarts/jquery.orgchart.js (这个是调试时用的,production要用min版)
效果图
注:上图与官方图有样式区别,是因我修改原代码中的css以适应多分支的情况,由图可见当分支太多时,orgchart显示起来还是太拥挤了。(官方图如下)
|