tooltip 给单个数据设置

 

option = {
    backgroundColor: '#1a4377',
    tooltip: {},
    toolbox: {
        feature: {
            saveAsImage: {},
        },
    },
    series: [
        {
            type: 'graph',
            layout: 'force',
            force: {
                repulsion: 1500,
                edgeLength: 120,
                layoutAnimation: true,
            },
            symbolSize: 70,
            nodeScaleRatio: 1, //图标大小是否随鼠标滚动而变
            roam: true, //缩放
            draggable: true, //节点是否可以拖拽
            edgeSymbol: ['none', 'arrow'], //线2头标记
            label: {
                normal: {
                    show: true,
                    position: 'inside',
                    color: '#FFF',
                },
            },
            edgeLabel: {
                normal: {
                    show: true,
                    textStyle: {
                        fontSize: 12,
                        color: '#FFF',
                    },
                    formatter: '{c}',
                },
            },
            symbolKeepAspect: false,
            focusNodeAdjacency: false, // 指定的节点以及其所有邻接节点高亮
            itemStyle: {
                normal: {
                    borderColor: '#29ACFC',
                    borderWidth: 2,
                    shadowColor: '#29ACFC',
                    color: '#29ACFC',
                    curveness: 0.08,
                },
            },

            lineStyle: {
                normal: {
                    opacity: 0.9,
                    width: 2,
                    curveness: 0.15,
                    color: {
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [
                            {
                                offset: 0,
                                color: '#FFF', // 0% 处的颜色
                            },
                            {
                                offset: 1,
                                color: '#FFF', // 100% 处的颜色
                            },
                        ],
                        globalCoord: false,
                    },
                },
            },

            data: [
                {
                    name: '李富贵',
                    tooltip: {
                        formatter: '{b} <br/>性别:男<br/>职务:富阳区灵桥镇灵桥村务农',
                    },
                    itemStyle: {
                        normal: {
                            color: '#FCBB5B',
                            borderColor: '#FCBB5B',
                            shadowColor: '#FCBB5B',
                        },
                    },
                },
                {
                      tooltip: {
                        formatter: '{b} <br/>性别:男<br/>出生年月:19951114<br/>星座:处女座',
                    },
                    name: '王桂花',
                },
                {
                      tooltip: {
                        formatter: '{b} <br/>性别:男<br/>出生年月:19951114<br/>星座:处女座',
                    },
                    name: '李思思',
                },
                {
                    name: '自住房屋',
                },
                {
                    name: '车子',
                },
                {
                    name: '租房',
                },
                {
                    name: '黄涛',
                },
                {
                    name: '于海',
                },
                {
                    name: '张柏',
                },
                {
                    name: '付梦杰',
                },
            ],
            links: [
                {
                    source: 0,
                    target: 1,
                    value: '夫妻',
                },
                {
                    source: 0,
                    target: 2,
                    value: '父亲',
                },
                {
                    source: 2,
                    target: 0,
                    value: '女儿',
                },
                {
                    source: 0,
                    target: 3,
                    value: '自住',
                },
                {
                    source: 0,
                    target: 4,
                    value: '车主',
                },
                {
                    source: 0,
                    target: 5,
                    value: '租户',
                },
                {
                    source: 5,
                    target: 6,
                    value: '租赁',
                },
                {
                    source: 5,
                    target: 7,
                    value: '租赁',
                },
                {
                    source: 5,
                    target: 8,
                    value: '租赁',
                },
                {
                    source: 5,
                    target: 9,
                    value: '租赁',
                },
            ],
        },
    ],
};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ECharts一个非常强大的数据可视化库,其地图组件提供了丰富的交互功能,包括地图 tooltip(工具提示)。在 ECharts 地图中,tooltip 可以设置为轮播模式,这意味着当鼠标悬停在地图上时,会显示一系列相关的数据点,而不是只显示单个数据点的信息。 轮播 tooltip 的配置通常涉及到以下步骤: 1. **设置 tooltip 类型**:在地图配置中,指定 tooltip 的类型为 `map`,并设置 `show` 为 `true`。 ```javascript option = { tooltip: { type: 'map', show: true, trigger: 'item', // 或者 'emphasis' axisPointer: { // 鼠标移动到地图上时的指示线 type: 'shadow' }, formatter: function (params) { // 自定义 tooltip 内容显示 return params.name + '<br>' + params.value; } }, ... }; ``` 2. **关联地理编码信息**:在地图数据中,每个区域需要有一个 `name` 属性对应地图上的名称,并可能包含其他用于轮播的数据,如 `data` 数组。 ```javascript series: [{ name: '地图数据', type: 'map', mapType: 'yourMapType', // 例如 'world', 'china' 等 data: [ { name: '区域1', value: value1, // 区域1的数据 } { name: '区域2', value: value2, // 区域2的数据 } ... ], ... }] ``` 3. **轮播配置**:ECharts 提供了 `formatter` 函数,你可以自定义这个函数,使其根据数据内容动态展示。如果数据数组较大,你可以控制 tooltip 显示哪些数据点,例如,可以通过索引或轮播显示前几项。 ```javascript formatter: function (params) { let content = ''; for (let i = 0; i < params.data.length && i < 3; i++) { // 轮播3个数据点 content += `<div>${params.data[i].name}: ${params.data[i].value}</div>`; } return content; } ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值