Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在工具提示中显示Highcharts x轴时间戳标签?_Javascript_Jquery_Highcharts - Fatal编程技术网

Javascript 如何在工具提示中显示Highcharts x轴时间戳标签?

Javascript 如何在工具提示中显示Highcharts x轴时间戳标签?,javascript,jquery,highcharts,Javascript,Jquery,Highcharts,在我的图表中,这些时间戳显示在x轴上 当我将鼠标悬停在图表中的某个点上时,如何使它们显示在工具提示中 Highcharts.chart('container', { ... xAxis: { labels: { formatter: function() { let seconds = this.value * 5; let t = new Date(1900, 1, 1, 9, 30, 0);

在我的图表中,这些时间戳显示在x轴上

当我将鼠标悬停在图表中的某个点上时,如何使它们显示在工具提示中

Highcharts.chart('container', {
    ...
    xAxis: {
      labels: {
        formatter: function() {
          let seconds = this.value * 5;
          let t = new Date(1900, 1, 1, 9, 30, 0);
          t.setSeconds(t.getSeconds() + this.value * 5);
          return `${t.getHours()}:${t.getMinutes()}:${t.getSeconds()}`
        }
      },
      tickInterval: 2
    },
 });

有人能帮我一下吗,因为我无法理解这个问题。

Highcharts API有一个用于工具提示的pointFormat属性,您可以在其中指定HTML(例如,
工具提示数据:{variable}

)。您可以在此处找到API参考:


或者您可以使用pointFormatter来指定回调函数()。

您可以在
pointFormatter
中使用与标签格式化程序函数相同的方法

            tooltip: {
                pointFormatter: function(){
                    let t = new Date(1900, 1, 1, 9, 30, 0);
                    t.setSeconds(t.getSeconds() + this.x * 5);
                    
                    return `
                        Time: ${t.getHours()}:${t.getMinutes()}:${t.getSeconds()}
                        Y: ${this.y} 
                        Value: ${this.value}
                    `
                }
            }

现场演示:

API参考: