145Echarts - 矩形树图(Show Parent Labels)

效果图

在这里插入图片描述

源代码
myChart.showLoading();

$.get('data/asset/data/disk.tree.json', function (diskData) {
    myChart.hideLoading();

    function colorMappingChange(value) {
        var levelOption = getLevelOption(value);
        chart.setOption({
            series: [{
                levels: levelOption
            }]
        });
    }

    var formatUtil = echarts.format;

    function getLevelOption() {
        return [
            {
                itemStyle: {
                    normal: {
                        borderColor: '#777',
                        borderWidth: 0,
                        gapWidth: 1
                    }
                },
                upperLabel: {
                    normal: {
                        show: false
                    }
                }
            },
            {
                itemStyle: {
                    normal: {
                        borderColor: '#555',
                        borderWidth: 5,
                        gapWidth: 1
                    },
                    emphasis: {
                        borderColor: '#ddd'
                    }
                }
            },
            {
                colorSaturation: [0.35, 0.5],
                itemStyle: {
                    normal: {
                        borderWidth: 5,
                        gapWidth: 1,
                        borderColorSaturation: 0.6
                    }
                }
            }
        ];
    }

    myChart.setOption(option = {

        title: {
            text: 'Disk Usage',
            left: 'center'
        },

        tooltip: {
            formatter: function (info) {
                var value = info.value;
                var treePathInfo = info.treePathInfo;
                var treePath = [];

                for (var i = 1; i < treePathInfo.length; i++) {
                    treePath.push(treePathInfo[i].name);
                }

                return [
                    '<div class="tooltip-title">' + formatUtil.encodeHTML(treePath.join('/')) + '</div>',
                    'Disk Usage: ' + formatUtil.addCommas(value) + ' KB',
                ].join('');
            }
        },

        series: [
            {
                name:'Disk Usage',
                type:'treemap',
                visibleMin: 300,
                label: {
                    show: true,
                    formatter: '{b}'
                },
                upperLabel: {
                    normal: {
                        show: true,
                        height: 30
                    }
                },
                itemStyle: {
                    normal: {
                        borderColor: '#fff'
                    }
                },
                levels: getLevelOption(),
                data: diskData
            }
        ]
    });
});
ECharts矩形树图(Treemap)是一种用于展示树形结构数据的图表类型。如果你想要调整矩形树图显示区域,可以通过设置图表容器的大小或者调整 ECharts 配置项中的相关参数来实现。以下是一些可能的调整方法: 1. 修改图表容器的大小:确保图表所在的 HTML 容器(通常是 `div` 元素)具有足够的宽度和高度。可以通过 CSS 样式直接设置容器的宽高,或者通过 JavaScript 动态设置。例如: ```html <!-- CSS 直接设置 --> <style> .container { width: 600px; height: 400px; } </style> <div class="container" id="treemap"></div> ``` 或者 ```javascript // JavaScript 动态设置 document.getElementById('treemap').style.width = '600px'; document.getElementById('treemap').style.height = '400px'; ``` 2. 使用 `roamScope` 属性:在 ECharts 的 `series` 配置中,有一个 `roamScope` 属性,它可以控制缩放和平移的范围。如果你想要限制缩放的比例,可以通过这个属性进行设置: ```javascript option = { series: [ { type: 'treemap', roamScope: [1, 2] // 这里设置缩放范围,例如限制在1倍到2倍之间 } ] }; ``` 3. 调整布局方式:如果你是想调整数据块的显示密度,可以通过调整布局参数来实现。比如 `layout` 的 `width` 和 `height` 属性,可以用来控制树图的布局大小: ```javascript option = { series: [ { type: 'treemap', layout: 'none', label: { emphasis: { show: true, fontSize: 20 // 根据需要调整字体大小 } }, leaves: { label: { position: 'bottom', verticalAlign: 'middle', align: 'left', fontSize: 14 // 根据需要调整字体大小 } }, layoutSize: '100%', // 这里可以设置布局的大小 layoutDirection: 'ltr', // 从左到右布局 data: yourData // 你的数据源 } ] }; ``` 请根据你的具体情况,选择合适的调整方法,以达到预期的显示效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值