【问题标题】:how to convert timestamp in date format in tooltip of highcharts?如何在highcharts的工具提示中转换日期格式的时间戳?
【发布时间】:2019-04-30 10:44:36
【问题描述】:

在这里,我在我的 react 项目中使用了 line highcharts,在我的 line highchart 中我显示了工具提示,在这个工具时间里我有一个日期,但是这个日期是时间戳格式,我想在工具提示中以日期格式显示这个时间戳可能在 highcharts 工具提示中?

 tooltip: {
    headerFormat: '<b>{series.name}</b>',
    pointFormat: '{point.x}',  // 1554422400
  },

【问题讨论】:

标签: highcharts


【解决方案1】:

使用 moment.js npm,专用于时间和日期和时间的所有相关格式

【讨论】:

    【解决方案2】:

    pointFormatter函数中可以使用HighchartsdateFormat方法:

    tooltip: {
        ...,
        pointFormatter: function() {
            return Highcharts.dateFormat('%a %d %b %H:%M:%S', this.x)
        }
    }
    

    现场演示: http://jsfiddle.net/BlackLabel/oLt62kbu/

    API 参考:

    https://api.highcharts.com/class-reference/Highcharts#.dateFormat

    https://api.highcharts.com/highcharts/tooltip.pointFormatter

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 2016-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-05
    相关资源
    最近更新 更多