zoukankan      html  css  js  c++  java
  • 手把手教你做echarts图表系列之组织结构图

    在实际项目中使用echarts越来越多了,今天从一个组织结构图开始,手把手教大家开发echarts图表。

    公司里的组织结构图如下:

    可以参考echarts入门教程:http://echarts.baidu.com/echarts2/doc/start.html

    完整代码实现:

    <!DOCTYPE html>
    <head>
        <meta charset="utf-8">
        <title>ECharts</title>
    </head>
    
    <body>
        <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
        <div id="main_orgStructure" style="1200px; height:400px;position: absolute; top: 10%; left: 10%;"></div>
        <!-- ECharts单文件引入 -->
        <script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
        <script type="text/javascript">
            // 路径配置
            require.config({
                paths: {
                    echarts: 'http://echarts.baidu.com/build/dist'
                }
            });
            // 使用
            require(
                [
                    'echarts',
                    'echarts/chart/tree' // 使用树状图就加载tree模块,按需加载
                ],
                function (ec) {
                    // 基于准备好的dom,初始化echarts图表
                    var myChart = ec.init(document.getElementById('main_orgStructure')); 
                    var commonStyle = {
                            
                    }
                    var option = {
                            title : {
                                text: '组织结构图'
                            },
                            tooltip : {
                                show: false,
                                trigger: 'item',
                                formatter: "{b}: {c}"
                            },
                            toolbox: {
                                show : true,
                                feature : {
                                    mark : {show: true},
                                    dataView : {show: true, readOnly: false},
                                    restore : {show: true},
                                    saveAsImage : {show: true}
                                }
                            },
                            calculable : false,
                            series : [
                                {
                                    name:'树图',
                                    type:'tree',
                                    orient: 'vertical',  // vertical horizontal
                                    rootLocation: {x: '50%', y: '15%'}, // 根节点位置  {x: 'center',y: 10}
                                    nodePadding: 20,
                                    layerPadding:40,
                                    symbol: 'rectangle',
                                    borderColor:'black',
                                    itemStyle: {
                                        normal: {
                                              color: '#fff',//节点背景色
                                            label: {
                                                show: true,
                                                position: 'inside',
                                                textStyle: {
                                                    color: 'black',
                                                    fontSize: 15,
                                                    //fontWeight:  'bolder'
                                                }
                                            },
                                            lineStyle: {
                                                color: '#000',
                                                 1,
                                                type: 'broken' // 'curve'|'broken'|'solid'|'dotted'|'dashed'
                                            }
                                        },
                                        emphasis: {
                                            label: {
                                                show: false
                                            }
                                        }
                                    },
                                    data: [
                                        {
                                            name: '董事会',
                                                value: 6,
                                                symbolSize: [70, 30],
                                                symbol: 'rectangle',
                                                itemStyle: {
                                                    normal: {
                                                        borderWidth: 2,
                                                        borderColor: 'black'
                                                    }
                                                },
                                                children: [
                                            {
                                                name: '总经理',
                                                value: 6,
                                                symbolSize: [70, 30],
                                                symbol: 'rectangle',
                                                itemStyle: {
                                                    normal: {
                                                        borderWidth: 2,
                                                        borderColor: 'black'
                                                    }
                                                },
                                                children: [
                                                    {
                                                        name: '营销中心',
                                                        value: 4,
                                                        symbolSize: [70, 30],
                                                        symbol: 'rectangle',
                                                        itemStyle: {
                                                            normal: {
                                                                label: {
                                                                    show: true,
                                                                    position: 'inside'
                                                                },
                                                                borderWidth: 2,
                                                                borderColor: 'black'
                                                            }
                                                        },
                                                        children: [
                                                            {
                                                                name: '市场部',
                                                                value: 4,
                                                                symbolSize: [60, 30],
                                                                symbol: 'rectangle',
                                                                itemStyle: {
                                                                    normal: {
                                                                        label: {
                                                                            show: true,
                                                                            position: 'inside'
                                                                        },
                                                                        borderWidth: 2,
                                                                        borderColor: 'black'
                                                                    }
                                                                },
                                                            },
                                                            {
                                                               name: '销售部',
                                                                value: 4,
                                                                symbolSize: [60, 30],
                                                                symbol: 'rectangle',
                                                                itemStyle: {
                                                                    normal: {
                                                                        label: {
                                                                            show: true,
                                                                            position: 'inside'
                                                                        },
                                                                        borderWidth: 2,
                                                                        borderColor: 'black'
                                                                    }
                                                                },
                                                            },
                                                            {
                                                                name: '客服部',
                                                                value: 4,
                                                                symbolSize: [60, 30],
                                                                symbol: 'rectangle',
                                                                itemStyle: {
                                                                    normal: {
                                                                        label: {
                                                                            show: true,
                                                                            position: 'inside'
                                                                        },
                                                                        borderWidth: 2,
                                                                        borderColor: 'black'
                                                                    }
                                                                },
                                                            }
                                                        ]
                                                    },
                                                    {
                                                        name: '项目中心',
                                                        value: 4,
                                                        symbolSize: [70, 30],
                                                        symbol: 'rectangle',
                                                        itemStyle: {
                                                            normal: {
                                                                label: {
                                                                    show: true,
                                                                    position: 'inside'
                                                                },
                                                                borderWidth: 2,
                                                                borderColor: 'black'
                                                            }
                                                        },
                                                        children: [
                                                            {
                                                                name: '售前支持部',
                                                                value: 4,
                                                                symbolSize: [90, 30],
                                                                symbol: 'rectangle',
                                                                itemStyle: {
                                                                    normal: {
                                                                        label: {
                                                                            show: true,
                                                                            position: 'inside'
                                                                        },
                                                                        borderWidth: 2,
                                                                        borderColor: 'black'
                                                                    }
                                                                },
                                                            },
                                                            {
                                                               name: '项目一部',
                                                                value: 4,
                                                                symbolSize: [70, 30],
                                                                symbol: 'rectangle',
                                                                itemStyle: {
                                                                    normal: {
                                                                        label: {
                                                                            show: true,
                                                                            position: 'inside'
                                                                        },
                                                                        borderWidth: 2,
                                                                        borderColor: 'black'
                                                                    }
                                                                },
                                                            },
                                                            {
                                                                 name: '项目二部',
                                                                value: 4,
                                                                symbolSize: [70, 30],
                                                                symbol: 'rectangle',
                                                                itemStyle: {
                                                                    normal: {
                                                                        label: {
                                                                            show: true,
                                                                            position: 'inside'
                                                                        },
                                                                        borderWidth: 2,
                                                                        borderColor: 'black'
                                                                    }
                                                                },
                                                            },
                                                           {
                                                                 name: '项目三部',
                                                                value: 4,
                                                                symbolSize: [70, 30],
                                                                symbol: 'rectangle',
                                                                itemStyle: {
                                                                    normal: {
                                                                        label: {
                                                                            show: true,
                                                                            position: 'inside'
                                                                        },
                                                                        borderWidth: 2,
                                                                        borderColor: 'black'
                                                                    }
                                                                },
                                                            }
                                                        ]
                                                    },
                                                    {
                                                        name: '技术中心',
                                                        value: 4,
                                                        symbolSize: [70, 30],
                                                        symbol: 'rectangle',
                                                        itemStyle: {
                                                            normal: {
                                                                label: {
                                                                    show: true,
                                                                    position: 'inside'
                                                                },
                                                                borderWidth: 2,
                                                                borderColor: 'black'
                                                            }
                                                        },
                                                        children: [
                                                            {
                                                                name: '开发部',
                                                                value: 4,
                                                                symbolSize: [70, 30],
                                                                symbol: 'rectangle',
                                                                itemStyle: {
                                                                    normal: {
                                                                        label: {
                                                                            show: true,
                                                                            position: 'inside'
                                                                        },
                                                                        borderWidth: 2,
                                                                        borderColor: 'black'
                                                                    }
                                                                },
                                                            },
                                                            {
                                                               name: '设计部',
                                                                value: 4,
                                                                symbolSize: [70, 30],
                                                                symbol: 'rectangle',
                                                                itemStyle: {
                                                                    normal: {
                                                                        label: {
                                                                            show: true,
                                                                            position: 'inside'
                                                                        },
                                                                        borderWidth: 2,
                                                                        borderColor: 'black'
                                                                    }
                                                                },
                                                            },
                                                            {
                                                                 name: '系统部',
                                                                value: 4,
                                                                symbolSize: [70, 30],
                                                                symbol: 'rectangle',
                                                                itemStyle: {
                                                                    normal: {
                                                                        label: {
                                                                            show: true,
                                                                            position: 'inside'
                                                                        },
                                                                        borderWidth: 2,
                                                                        borderColor: 'black'
                                                                    }
                                                                },
                                                            }
                                                        ]
                                                    },
                                                    {
                                                        name: '行政部',
                                                        value: 4,
                                                        symbolSize: [70, 30],
                                                        symbol: 'rectangle',
                                                        itemStyle: {
                                                            normal: {
                                                                label: {
                                                                    show: true,
                                                                    position: 'inside'
                                                                },
                                                                borderWidth: 2,
                                                                borderColor: 'black'
                                                            }
                                                        }
                                                    },
                                                  {
                                                        name: '财务部',
                                                        value: 4,
                                                        symbolSize: [70, 30],
                                                        symbol: 'rectangle',
                                                        itemStyle: {
                                                            normal: {
                                                                label: {
                                                                    show: true,
                                                                    position: 'inside'
                                                                },
                                                                borderWidth: 2,
                                                                borderColor: 'black'
                                                            }
                                                        }
                                                    },
                                                  {
                                                        name: '其他分支',
                                                        value: 4,
                                                        symbolSize: [70, 30],
                                                        symbol: 'rectangle',
                                                        itemStyle: {
                                                            normal: {
                                                                label: {
                                                                    show: true,
                                                                    position: 'inside'
                                                                },
                                                                borderWidth: 2,
                                                                borderColor: 'black'
                                                            }
                                                        },
                                                        children: [
                                                            {
                                                                name: '汕头分公司',
                                                                value: 4,
                                                                symbolSize: [90, 30],
                                                                symbol: 'rectangle',
                                                                itemStyle: {
                                                                    normal: {
                                                                        label: {
                                                                            show: true,
                                                                            position: 'inside'
                                                                        },
                                                                        borderWidth: 2,
                                                                        borderColor: 'black'
                                                                    }
                                                                },
                                                            }
                                                        ]
                                                    },
                                                ]
                                            }]
                                        }
                                    ]
                                }
                            ]
                        };                            
                    // 为echarts对象加载数据 
                    myChart.setOption(option);
                });
        </script>
    </body>
  • 相关阅读:
    Ajax实现文件下载
    jquery easyui 插件开发
    Chrome谷歌浏览器首页被改为Hao123导航怎么办|附各类解决方法【转】
    查看mysql版本的四种方法
    IntelliJ IDEA 快捷键大全
    Java中判断字符串是否为数字的五种方法
    比数据分析更要命的是:数据质量
    Python绘制六种可视化图表详解,三维图最炫酷!你觉得呢?
    大数据需要好设计
    Python模块学习filecmp文件比较
  • 原文地址:https://www.cnblogs.com/lingluo2017/p/6963215.html
Copyright © 2011-2022 走看看