【问题标题】:highchart x axis not showing correct date labelshighchart x 轴未显示正确的日期标签
【发布时间】:2023-04-05 07:30:01
【问题描述】:

我正在使用 highchart 并动态加载 json。 json 为我提供了日期时间序列及其值

正在创建图表,工具提示显示正确的值 只有 x 轴标签没有正确显示。

  $(function () {
        $('#container').highcharts({
            xAxis: {
                type: 'datetime',
                dateTimeLabelFormats: {
                    day: '%e of %b'
                }
            },

            series: [{
                data: [
["2013-09-15 08:44:37",19.8],
["2013-09-18 08:47:37",18.4],
["2013-09-19 08:50:37",18.3],
["2013-09-20 08:53:37",18.1]
    ],
                //pointStart: Date.UTC(2010, 0, 1),
                pointInterval: 24 * 3600 * 1000 // one day
            }]
        });
    });

现场直播:http://plnkr.co/edit/TfcJVPpqu6ZM2LywKmO5?p=preview

请提供帮助。谢谢

编辑

我已经用正确的日期更新了帖子和 plunkr

【问题讨论】:

    标签: javascript json charts highcharts timeserieschart


    【解决方案1】:

    尝试将日期设为getTime(毫秒)格式:

    [new Date("2013-09-15T08:44:37").getTime(),19.8],
    [new Date("2013-09-18T08:47:37").getTime(),18.4],
    [new Date("2013-09-19T08:50:37").getTime(),18.3],
    [new Date("2013-09-20T08:53:37").getTime(),18.1]
    

    如this plunker。

    【讨论】:

    • 任何其他方式这样做..我的意思是如果我不想使用 new Date().getTime() ?
    • highcharts 在使用日期时间时需要毫秒,因此您需要以某种方式计算它。您可以使用任何其他方法来获取毫秒,例如:Date.UTC 函数
    猜你喜欢
    • 2018-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-09
    • 2021-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多