antvis/G2

[v5]: interaction( type:tooltip ) item函数能放上对象数据吗? #4433

Valar103769 posted onGitHub

接口返回

[
{hour:"2020-12-02 23"},
{hour:"2020-12-03 23"},
]

需要展示两天,23时的数据,

 .encode('x', (d) => Number(dayjs(d.hour, 'YYYY-MM-DD HH').format('HH'))) //  x轴显示23时
但是tooltip需要显示 2020-12-02 23 和2020-12-03 23 ,就处理不了啊

<img width="355" alt="image" src="https://user-images.githubusercontent.com/36926073/206620589-f1d7d797-f50c-4148-859d-634a5a85b16f.png">


按照下面的写法就可以拿到 '2020-12-02 23' 和 '2020-12-03 23'

function render() {
  line
    .data(data)
    .encode('x', 'hour')
    .axis('x', {
      labelFormatter: (hour) =>
        Number(dayjs(hour, 'YYYY-MM-DD HH').format('HH')),
    });
}

或者把 X 通道转换成 Date 对象,但这样就是一个连续的 x 轴

function render() {
  line
    .data(data)
    .encode('x', d => dayjs(d.hour, "YYYY-MM-DD HH").toDate())
}

tooltip 拿到更多的信息相关的 API 目前还在设计中,可能下周或者下下周的版本会体现。

posted by pearmini over 2 years ago

Fund this Issue

$0.00
Funded

Pull requests