Anystock注解xAnchor无法识别小时级时间 标注线定位错误如何解决
问题根因
AnyStock 默认对传入的字符串类型xAnchor仅解析到日级精度,时分秒部分会被自动忽略,所以标注线会定位到当天起始位置。
修复方案
不要直接传入日期字符串,而是先将时间转换为时间戳,或调用AnyStock内置的日期解析方法显式解析完整时间字符串,保留时分秒精度。
修改后的代码如下:
// create annotation var annotation = plot.annotations(); // create annotation vertical line annotation .verticalLine({ // 方式1:用anychart.date.parse显式解析带时分秒的时间字符串 xAnchor: anychart.date.parse('2009-07-02 15:15:00'), // 方式2:直接传入对应时间的毫秒级时间戳 // xAnchor: 1246528500000, stroke: { thickness: 2, color: '#60727B', dash: '10 15' } // disable interaction with Annotation }) .allowEdit(false);
补充说明
如果你的图表数据源本身已经是时间戳格式,建议直接对齐使用时间戳传入xAnchor,避免不同时区解析带来的偏移问题。
内容的提问来源于stack exchange,提问作者saltuklev
相关产品推荐
相关产品推荐

