Chart.js工具提示显示错误的日期

时间:2020-04-29 15:50:04

标签: chart.js tooltip

chart.js中的工具提示出现以下问题:

在添加tooltipFormat之前,我的图表工作正常。

my data

chart without tooltipFormat-part1

chart without tooltipFormat-part2

chart with tooltipFormat-part1

chart with tooltipFormat-part2

xAxes: [{
                type: 'time',
                distribution: 'series',
                time: {
                    // tooltipFormat: tooltipFormat     // original code
                    tooltipFormat : 'YYYY-MM-DD HH:mm:SS ZZ',   //added for debugging
                    bounds: 'ticks',
                    round: false,
                    unit: chartUnit,
                    displayFormats: {
                        hour: timeFormat,
                        day: dateFormatDay,
                        month: dateFormatMonth,
                        year: dateFormatYear
                    }
                },
                offset: true,
                ticks: {
                    autoSkip: false,
                    source: 'label'
                }
            }]

在前两张图片中,您可以看到工具提示中的代码中没有任何tooltipFormat(两行都作为注释)。想象中的一切都还可以。每个数据集都在正确的位置,并且具有正确的日期/时间。

我的原始问题是,我想以与轴上相同的格式显示日期。但是对于每个月(实际月份除外),工具提示上有一个日期,而轴上的日期为一个月。数据本身位于正确的位置。 因此,我添加了行tooltipFormat : 'YYYY-MM-DD HH:mm:SS ZZ',进行调试。 如您在第二张图像上看到的,如果我添加此行,则工具提示中的日期会更改。实际月份的装备时间为+2,但过去的所有日期都更改为23:00:00,其时区为+1。

有人可以帮助我弄明白为什么会这样吗?

谢谢您的好意, 迈克尔

0 个答案:

没有答案