apache / echarts

Apache ECharts is a powerful, interactive charting and data visualization library for browser
https://echarts.apache.org
Apache License 2.0
60.81k stars 19.62k forks source link

legend定位问题 #5505

Closed zhangch-fnst closed 7 years ago

zhangch-fnst commented 7 years ago

One-line summary [问题简述]

legend:{ top : '8%', left: '20%', ...} 如上,设置图例的位置,当浏览器的缩放比例调整时,图例的位置会错乱。 有何方法可以解决该问题? 这是浏览器缩放比例100%时,图例与色块div并排显示,显示正常:如下图 snap1

当浏览器缩放比例80%时,图例相对于整个页面的位置会向上跑,与色块div不并排显示:如下图 snap3

照理来说,top和left用百分比设置后,当浏览器缩放时相对位置不会变动。 legend要怎样设置才能当浏览器缩放时相对位置不会变动。

Version & Environment [版本及环境]

Expected behaviour [期望结果]

如何设置图例的位置,才能当浏览器的缩放比例调整时,图例的位置不会错乱

ECharts option [ECharts配置项]

option = {
    "color": [
        "#C7C7C7",
        "#C7C7C7",
        "#C7C7C7",
        "#C7C7C7",
        "#FFB6C1",
        "#FFB6C1",
        "#FFB6C1",
        "#FFB6C1",
        "#FF69B4",
        "#FF69B4",
        "#FF69B4",
        "#FF69B4",
        "#FF1493",
        "#FF1493",
        "#FF1493",
        "#FF1493",
        "#D02090",
        "#D02090",
        "#D02090",
        "#D02090",
        "#A52A2A",
        "#A52A2A",
        "#A52A2A",
        "#A52A2A"
    ],
    "tooltip": {
        "show": true,
        "showContent": true,
        "trigger": "item",
        "triggerOn": "mousemove",
        "alwaysShowContent": false,
        "showDelay": 0,
        "hideDelay": 200,
        "enterable": false,
        "position": "right",
        "confine": false,
        "transitionDuration": 0.4
    },
    "legend": {
        "show": true,
        "top": "8%",
        "left": "20%",
        "data": [
            {
                "name": "VM_0",
                "icon": "circle"
            },
            {
                "name": "DataStore_0",
                "icon": "rect"
            },
            {
                "name": "Esxi_0",
                "icon": "diamond"
            },
            {
                "name": "raid_0",
                "icon": "roundRect"
            }
        ]
    },
    "series": [
        {
            "type": "graph",
            "name": "Tool",
            "layout": "force",
            "legendHoverLink": true,
            "hoverAnimation": true,
            "coordinateSystem": null,
            "xAxisIndex": 0,
            "yAxisIndex": 0,
            "force": {
                "repulsion": 100,
                "gravity": 0.03,
                "edgeLength": 80,
                "layoutAnimation": true
            },
            "roam": true,
            "nodeScaleRatio": 0.6,
            "draggable": false,
            "focusNodeAdjacency": true,
            "edgeSymbol": [
                "none",
                "arrow"
            ],
            "edgeSymbolSize": 10,
            "itemStyle": {
                "normal": {
                    "label": {
                        "show": true
                    },
                    "borderType": "solid",
                    "borderColor": "#000000",
                    "borderWidth": 2,
                    "opacity": 1
                },
                "emphasis": {}
            },
            "lineStyle": {
                "normal": {
                    "color": "#A9A9A9",
                    "width": "3",
                    "type": "solid",
                    "curveness": 0.3,
                    "opacity": 1
                },
                "emphasis": {}
            },
            "label": {
                "normal": {
                    "show": true,
                    "position": "inside",
                    "textStyle": {
                        "color": "#000000",
                        "fontStyle": "normal",
                        "fontWeight": "bolder",
                        "fontFamily": "sans-serif",
                        "fontSize": 12
                    }
                },
                "emphasis": {}
            },
            "edgeLabel": {
                "normal": {
                    "show": false
                },
                "emphasis": {}
            },
            "data": [
                {
                    "id": "30",
                    "name": "datastore-eternus",
                    "category": 1,
                    "value": 0,
                    "symbol": "rect",
                    "symbolSize": 60
                },
                {
                    "id": "31",
                    "name": "10.25.212.238",
                    "category": 2,
                    "value": 0,
                    "symbol": "diamond",
                    "symbolSize": 60
                },
                {
                    "id": "32",
                    "name": "datastore1",
                    "category": 5,
                    "value": 1,
                    "symbol": "rect",
                    "symbolSize": 60
                },
                {
                    "id": "38",
                    "name": "10.25.212.168",
                    "category": 2,
                    "value": 0,
                    "symbol": "diamond",
                    "symbolSize": 60
                },
                {
                    "id": "33",
                    "name": "新規仮想マシン 2",
                    "category": 0,
                    "value": 0,
                    "symbol": "circle",
                    "symbolSize": 60
                },
                {
                    "id": "34",
                    "name": "新規仮想マシン 1",
                    "category": 4,
                    "value": 1,
                    "symbol": "circle",
                    "symbolSize": 60
                },
                {
                    "id": "35",
                    "name": "新規仮想マシン",
                    "category": 0,
                    "value": 0,
                    "symbol": "circle",
                    "symbolSize": 60
                },
                {
                    "id": "36",
                    "name": "testvm",
                    "category": 0,
                    "value": 0,
                    "symbol": "circle",
                    "symbolSize": 60
                },
                {
                    "id": "37",
                    "name": "datastore-icapf",
                    "category": 1,
                    "value": 0,
                    "symbol": "rect",
                    "symbolSize": 60
                },
                {
                    "id": "47",
                    "name": "user0",
                    "category": 3,
                    "value": 0,
                    "symbol": "roundRect",
                    "symbolSize": 60
                },
                {
                    "id": "39",
                    "name": "nfs01",
                    "category": 1,
                    "value": 0,
                    "symbol": "rect",
                    "symbolSize": 60
                },
                {
                    "id": "40",
                    "name": "qnet-nfs-datastore1",
                    "category": 1,
                    "value": 0,
                    "symbol": "rect",
                    "symbolSize": 60
                },
                {
                    "id": "41",
                    "name": "hotsuka_bootstrap2",
                    "category": 4,
                    "value": 1,
                    "symbol": "circle",
                    "symbolSize": 60
                },
                {
                    "id": "42",
                    "name": "kiban01",
                    "category": 20,
                    "value": 1024,
                    "symbol": "circle",
                    "symbolSize": 60
                },
                {
                    "id": "43",
                    "name": "kiban04",
                    "category": 4,
                    "value": 1,
                    "symbol": "circle",
                    "symbolSize": 60
                },
                {
                    "id": "44",
                    "name": "kiban02",
                    "category": 4,
                    "value": 1,
                    "symbol": "circle",
                    "symbolSize": 60
                },
                {
                    "id": "45",
                    "name": "kiban03",
                    "category": 4,
                    "value": 1,
                    "symbol": "circle",
                    "symbolSize": 60
                },
                {
                    "id": "46",
                    "name": "qnet01",
                    "category": 4,
                    "value": 1,
                    "symbol": "circle",
                    "symbolSize": 60
                }
            ],
            "categories": [
                {
                    "name": "VM_0",
                    "symbol": "circle"
                },
                {
                    "name": "DataStore_0",
                    "symbol": "rect"
                },
                {
                    "name": "Esxi_0",
                    "symbol": "diamond"
                },
                {
                    "name": "raid_0",
                    "symbol": "roundRect"
                },
                {
                    "name": "VM_1",
                    "symbol": "circle"
                },
                {
                    "name": "DataStore_1",
                    "symbol": "rect"
                },
                {
                    "name": "Esxi_1",
                    "symbol": "diamond"
                },
                {
                    "name": "raid_1",
                    "symbol": "roundRect"
                },
                {
                    "name": "VM_2",
                    "symbol": "circle"
                },
                {
                    "name": "DataStore_2",
                    "symbol": "rect"
                },
                {
                    "name": "Esxi_2",
                    "symbol": "diamond"
                },
                {
                    "name": "raid_2",
                    "symbol": "roundRect"
                },
                {
                    "name": "VM_3",
                    "symbol": "circle"
                },
                {
                    "name": "DataStore_3",
                    "symbol": "rect"
                },
                {
                    "name": "Esxi_3",
                    "symbol": "diamond"
                },
                {
                    "name": "raid_3",
                    "symbol": "roundRect"
                },
                {
                    "name": "VM>3",
                    "symbol": "circle"
                },
                {
                    "name": "DataStore>3",
                    "symbol": "rect"
                },
                {
                    "name": "Esxi>3",
                    "symbol": "diamond"
                },
                {
                    "name": "raid>3",
                    "symbol": "roundRect"
                },
                {
                    "name": "VM_Fail",
                    "symbol": "circle"
                },
                {
                    "name": "DataStore_Fail",
                    "symbol": "rect"
                },
                {
                    "name": "Esxi_Fail",
                    "symbol": "diamond"
                },
                {
                    "name": "raid_Fail",
                    "symbol": "roundRect"
                }
            ],
            "links": [
                {
                    "source": "30",
                    "target": "31"
                },
                {
                    "source": "32",
                    "target": "31"
                },
                {
                    "source": "32",
                    "target": "38"
                },
                {
                    "source": "33",
                    "target": "31"
                },
                {
                    "source": "34",
                    "target": "31"
                },
                {
                    "source": "34",
                    "target": "32"
                },
                {
                    "source": "35",
                    "target": "31"
                },
                {
                    "source": "36",
                    "target": "31"
                },
                {
                    "source": "37",
                    "target": "38"
                },
                {
                    "source": "37",
                    "target": "47"
                },
                {
                    "source": "39",
                    "target": "38"
                },
                {
                    "source": "40",
                    "target": "38"
                },
                {
                    "source": "41",
                    "target": "32"
                },
                {
                    "source": "41",
                    "target": "38"
                },
                {
                    "source": "42",
                    "target": "32"
                },
                {
                    "source": "42",
                    "target": "38"
                },
                {
                    "source": "43",
                    "target": "32"
                },
                {
                    "source": "43",
                    "target": "38"
                },
                {
                    "source": "44",
                    "target": "32"
                },
                {
                    "source": "44",
                    "target": "38"
                },
                {
                    "source": "45",
                    "target": "32"
                },
                {
                    "source": "45",
                    "target": "38"
                },
                {
                    "source": "46",
                    "target": "32"
                },
                {
                    "source": "46",
                    "target": "38"
                }
            ]
        }
    ]
}

Other comments [其他信息]

mangoZT commented 7 years ago

能不能截个图啊 legend目前是会自动换行的

zhangch-fnst commented 7 years ago

问题描述中追加了截图,请参照。

mangoZT commented 7 years ago

缩放等于可视区域变大 你百分比设置自然会按比例向左移 可否设置center

zhangch-fnst commented 7 years ago

明白了。谢谢