ant-design / ant-design-charts

A React Chart Library
https://ant-design-charts.antgroup.com/
MIT License
1.95k stars 364 forks source link

🐛[BUG] tooltip如何修改title名称 #2689

Closed rookie-luochao closed 2 months ago

rookie-luochao commented 2 months ago

tooltip

🐛 bug 描述 [详细地描述 bug,让大家都能理解]

图中value名称如何修改成使用x轴名称('colorField')

📷 复现步骤 [清晰描述复现步骤,让别人也能看到问题]

看图

🏞 期望结果 [描述你原本期望看到的结果]

看图

💻 复现代码 [提供可复现的代码,仓库,或线上示例]

看图

© 版本信息

🚑 其他信息 [如截图等其他信息可以贴在这里]

lxfu1 commented 2 months ago
    tooltip:{
      items: [{ field: 'height', name: '123' }, {field: 'weight', name: '1234'}]
    }

    tooltip:{
      items: [{ channel: 'y', name: '123' }]
    }
NiuZhuang commented 1 month ago

1. 上述方法无效:

    tooltip:{
      items: [{ field: 'height', name: '123' }, {field: 'weight', name: '1234'}]
    }

    tooltip:{
      items: [{ channel: 'y', name: '123' }]
    }
image

2. 最终解决办法:

        interaction: {
            tooltip: {
                render: (e, { title, items }) => {

                    return (
                        <div key={title}>
                            <h4>{title}</h4>
                            {items.map((item) => {
                                const { name, value, color } = item

                                let val = _.isNil(value) ? '-' : value

                                if (name == 'dayToDayRatio') {
                                    val = `${val}%`
                                }
                                if (name == 'score') {
                                    val = isPercentageValueByKey(cardItem?.itemkey) ? `${val}%` : val
                                }

                                return (
                                    <div key={name}>
                                        <div style={{ margin: 0, display: 'flex', justifyContent: 'space-between' }}>
                                            <div>
                                                <span
                                                    style={{
                                                        display: 'inline-block',
                                                        width: 6,
                                                        height: 6,
                                                        borderRadius: '50%',
                                                        backgroundColor: color,
                                                        marginRight: 6,
                                                    }}
                                                ></span>
                                                <span>{axisTitleMap[name]}</span>
                                            </div>
                                            <b>{val}</b>
                                        </div>
                                    </div>
                                )
                            })}
                        </div>
                    )
                },
            },
        },