账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    echaert2里用tree做组织结构图, 格式化label不生效!!! 求助!!!
    20
    0

    <!DOCTYPE html>
    <html>

    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    
    <body>
        <div id="main" style="width: 1000px;height:1000px"></div>
    </body>
    <script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
    <script type="text/javascript">
        function eConsole(e) {
            console.log(e)
        }
        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'));
                var commonStyle = {
    
                }
                var ecConfig = require('echarts/config');
                myChart.on(ecConfig.EVENT.CLICK, eConsole);
                var option = {
                    title: {
                        text: '组织结构图'
                    },
                    tooltip: {
                        show: false
                    },
                    calculable: false,
                    itemStyle: {
                        normal: {
                            color: '#fff', //节点背景色
                            label: {
                                show: true,
                                position: 'right',
                                textStyle: {
                                    color: 'black',
                                    fontSize: 15,
                                    baseline: 'top'
                                },
                                formatter: function(a, b, c) {
                                    console.log(a)
                                    console.log(b)
                                    console.log(c)
                                    return '你好'
                                }
                            },
                            lineStyle: {
                                color: '#000',
                                width: 1,
                                type: 'broken' // 'curve'|'broken'|'solid'|'dotted'|'dashed'
                            },
                            textStyle: {
                                baseline: 'bottom'
                            }
                        },
                        emphasis: {
                            label: {
                                show: false
                            }
                        }
                    },
                    series: [{
                        roam: true,
                        name: '树图',
                        type: 'tree',
                        orient: 'vertical', // vertical horizontal
                        rootLocation: {
                            x: '50%',
                            y: '15%'
                        }, // 根节点位置  {x: 'center',y: 10}
                        nodePadding: 120,
                        layerPadding: 100,
                        symbol: 'image://http://www.iconpng.com/png/ecommerce-business/iphone.png',
                        symbolSize: [50, 80],
                        borderColor: 'black',
                        itemStyle: {
                            normal: {
                                color: '#fff', //节点背景色
                                label: {
                                    show: true,
                                    position: 'right',
                                    textStyle: {
                                        color: 'black',
                                        fontSize: 15,
                                        baseline: 'top'
                                    },
                                    formatter: function(a, b, c) {
                                        console.log(a)
                                        console.log(b)
                                        console.log(c)
                                        return '你好'
                                    }
                                },
                                lineStyle: {
                                    color: '#000',
                                    width: 1,
                                    type: 'broken' // 'curve'|'broken'|'solid'|'dotted'|'dashed'
                                },
                                textStyle: {
                                    baseline: 'bottom'
                                }
                            },
                            emphasis: {
                                label: {
                                    show: false
                                }
                            }
                        },
                        data: [{
                            name: '张三',
                            itemStyle: {
                                normal: {
                                    color: '#fff', //节点背景色
                                    label: {
                                        show: true,
                                        position: 'right',
                                        textStyle: {
                                            color: 'black',
                                            fontSize: 15,
                                            baseline: 'top'
                                        },
                                        formatter: function(a, b, c) {
                                            console.log(a)
                                            console.log(b)
                                            console.log(c)
                                            return '你好'
                                        }
                                    },
                                    lineStyle: {
                                        color: '#000',
                                        width: 1,
                                        type: 'broken' // 'curve'|'broken'|'solid'|'dotted'|'dashed'
                                    },
                                    textStyle: {
                                        baseline: 'bottom'
                                    }
                                },
                                emphasis: {
                                    label: {
                                        show: false
                                    }
                                }
                            },
                            children: [{
                                name: '张三'
                            }, {
                                name: '张三'
                            }, {
                                name: '张三',
                                children: [{
                                    name: '张三'
                                }, {
                                    name: '张三'
                                }]
                            }]
                        }]
                    }]
                }
                // 为echarts对象加载数据 
                myChart.setOption(option);
            });
    </script>
    

    </html>

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 纪念我们的曾经i 普通会员 1楼

      在echarts 2中,如果你使用了tree组件,并且想要设置label格式化,但 label 不生效,那么可能是因为你在创建树组件的时候,没有正确地设置其label属性。

      以下是一个示例,展示了如何在树组件中设置label:

      ```javascript var tree = echarts.init(document.getElementById('container'));

      var option = { tooltip: { trigger: 'item', formatter: '{a}: {b} ({x})
      }}, data: [{ name: 'Apple', value: 2 }, { name: 'Banana', value: 3 }], tree: { data: [{ id: '0', label: 'Apple' }, { id: '1', label: 'Banana' }], checkbox: { tooltip: { trigger: 'item', formatter: '{a}: {b} ({x})<br>} } } } };

      tree.setOption(option); ```

      在这个示例中,我们在创建树组件的时候,使用了checkbox属性,并设置了formatter属性为'{a}: {b} ({x})<br>',表示每一层节点的标签显示为它的id。然后在tree组件的setOption方法中,我们设置了data属性为[{'name': 'Apple', 'value': 2}, {'name': 'Banana', 'value': 3}],这个data数组中的每一项都是一个树节点的数据,其中的name属性是我们想要在标签中显示的名称,value属性是我们想要在标签中显示的值。

      如果你还是没有成功,那么可能是因为你的label属性没有生效,这可能是因为你没有正确地将其添加到checkbox组件的checkbox属性中。你可以尝试添加一个空的label属性,或者尝试将label属性添加到checkbox组件的checkbox属性中,并将checkbox属性的formatter属性设置为'{a}: {b} ({x})<br>'

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部