Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

框选对文本形式的时间数据不适用 #2591

Closed
SentretC opened this issue Jun 20, 2020 · 6 comments
Closed

框选对文本形式的时间数据不适用 #2591

SentretC opened this issue Jun 20, 2020 · 6 comments

Comments

@SentretC
Copy link
Contributor

官方示例https://g2.antv.vision/zh/examples/interaction/brush#element-brush中,若增加chart.scale('year', { type: 'time' });,则框选结果为空白
而如果原始数据为时间戳则可正常框选
似乎可以在range-filter.tsgetFilter函数中,像对待分类度量一样进行特殊处理解决

@lxj665294
Copy link

遇到同样问题,坐标格式为时间格式 如: "yyyy-MM-dd" "yyyy-MM-dd HH:mm:ss" 也会有同样问题,但是 "yyyyMMdd" 不会

@wzbooks
Copy link

wzbooks commented Jan 8, 2021

遇到同样问题,我也来反馈一下,时间格式为“HH:mm:ss”可以进行框选

@wzbooks
Copy link

wzbooks commented Jan 8, 2021

当我想使用度量的类型Scale的type为time时,antv要求传入"yyyy-MM-dd HH:mm:ss"格式的时间数据(因为当时间格式为HH:mm:ss,或时间戳时,js会报错“Invalid Time: 1609430412 in time scale!”),但是这种格式使用框选brush后会空白,令人头疼

@wzbooks
Copy link

wzbooks commented Jan 9, 2021

纠正一下我昨天的一个错误:使用时间戳js会报错“Invalid Time: 1609430412 in time scale!”,是因为我的时间戳是字符串类型导致,转成int类型就不报错了,也可以正常使用框选,所以时间戳是我的最终解决方案,需要注意一下:时间戳必须精确到“毫秒”,因为G2的time类型默认按毫秒转换,如果只精确到秒,会发现格式化后的时间不准确

@xmter
Copy link

xmter commented May 7, 2021

遇到同样问题,我也来反馈一下 时间为YYYY-MM-DD 框选空白,为MM-DD可以。

@hustcc
Copy link
Member

hustcc commented Aug 22, 2023

G2 v3 v4 中对于数据的识别是通过正则来的,如果匹配到属于日期正则的字符串,就判定为 date 或者 time,否则就会当做字符串 cat 去处理。

但是这个日期匹配的正则表达式经常出错,所以建议大家按照规范来写。另外,在 G2 5.0 中,我们强要求如果是日期类型的,那么数据就使用 Date 类型传入到 G2,避免应为正则匹配的不确定性带来程序的不确定性。

@hustcc hustcc closed this as completed Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants