组织结构图OrgChart.js

环境配置先引入两个文件:<link href="https://fonts.googleapis.com/css?family=Gochi+Hand" rel="stylesheet"><script type="text/jscript" src="https://balkangraph.com/js/latest/OrgChart.js"></script&...
摘要由CSDN通过智能技术生成

环境配置

先引入两个文件:
<link href="https://fonts.googleapis.com/css?family=Gochi+Hand" rel="stylesheet">
<script type="text/jscript" src="https://balkangraph.com/js/latest/OrgChart.js"></script>
先看一下简单的demo:
HTML部分很简单:
<div id="chart-container"></div>
js部分初始化:

初始化

	var chart = new OrgChart(document.getElementById("chart-container"), {
   
        nodeBinding: {
   
            field_0: "name",
        },
        nodes: [
            {
    id: 1, name: "Denny Curtis"},
            {
    id: 2, pid: 1, name: "Ashley Barnett" },
            {
    id: 3, pid: 1, name: "Caden Ellison" },
            {
    id: 4, pid: 2, name: "Elliot Patel" },
        ]
    });

导出

如果要将生成的组织结构图导出的话:

	  var chart = new OrgChart(document.getElementById("chart-container"), {
   
        menu: {
   
            pdf: {
    text: "Export PDF" },
            png: {
    text: "Export PNG" },
            svg: {
    text: "Export SVG" },
            csv: {
    text: "Export CSV" }
        },
        nodeMenu: {
   
            pdf: {
    text: "Export PDF" },
            png: {
    text: "Export PNG" },
            svg: {
    text: "Export SVG" }
        },
        ... 
    });

默认情况下折叠之后的子节点不会导出,如果要更改必须添加自己的导出节点菜单项

	function pdf(nodeId) {
   
            chart.exportPDF({
   filename: "MyFileName.pdf", expandChildren: true, nodeId: nodeId});
        }
    function png(nodeId) {
   
            chart.exportPNG({
   filename: "MyFileName.png", expandChildren: true, nodeId: nodeId});
        }
    function svg(nodeId) {
   
            chart.exportSVG({
   filename: "MyFileName.svg", expandChildren: true, nodeId: nodeId});
        }

    var chart = new OrgChart(document.getElementById("chart-container"), {
   
       menu: {
   
                export_pdf: {
   
                    text: "Export PDF",
                    icon: OrgChart.icon.pdf(24, 24, "#7A7A7A"),
                    onClick: pdf
                },
                export_png: {
   
                    text: "Export PNG",
                    icon: OrgChart.icon.png(24, 24, "#7A7A7A"),
                    onClick: png
                },
                export_svg: {
   
                    text: "Export SVG",
                    icon: OrgChart.icon.svg(24, 24, "#7A7A7A"),
                    onClick: svg
                }
            },
            nodeMenu: {
   
                export_pdf: {
   
                    text: "Export PDF",
                    icon: OrgChart.icon.pdf(24, 24, "#7A7A7A"),
                    onClick: pdf
                },
                export_png: {
   
                    text: "Export PNG",
                    icon: OrgChart.icon.png(24, 24, "#7A7A7A"),
                    onClick: png
                },
                export_svg: {
   
                    text: "Export SVG",
                    icon: OrgChart.icon.svg(24, 24, "#7A7A7A"),
                    onClick: svg
                }
            },
            ...
      });    

导出为A4格式:

 		function pdf(nodeId) {
   
           chart.exportPDF({
   
              format: "A4"
           }
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Swn_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值