Highcharts: X轴,MySQL日期时间

Highcharts: X axis, MySQL datetime

本文关键字:MySQL 日期 时间 Highcharts      更新时间:2023-09-26

我无法让highcharts识别我的时间戳,它们是javascript日期格式。
尝试了许多不同的方法,但是当数据和时间数组都是分开的时候,它不能工作。

小提琴:http://jsfiddle.net/SjL6F/

    $(function () {
    Highcharts.setOptions({
        lang: {
            thousandsSep: ''
        }
    });

    $('#container').highcharts({
        title: {
            text: 'Temperature - Last 24 hours',
        },
        credits: {
            enabled: false
        },
        subtitle: {
            text: "Test Site",
            x: -20
        },
        xAxis: {
            type: 'datetime',
            labels: {
                enabled: true
            },
            categories: time,
            tickInterval: 3600 * 1000,
            dateTimeLabelFormats: {
                day: '%e of %b'
            }
        },
        yAxis: [{
            title: {
                text: 'Temperature ('u00b0C)'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        }],
        tooltip: {
            shared: true
        },
        series: [{
            name: 'Temperature',
            data: temp,
            type: 'line',
            tooltip: {
                valueSuffix: ' C'
            },
            marker: {
                enabled: false
            }
        }]
    });
});

Highcharts只显示原始的javascript日期值。

您正在设置类别,这不是xAxis的日期时间类型。删除它们,然后连接时间和临时数组。

例如:

var concatenatedData = [];
$.each(time, function(i, e){
        concatenatedData.push([parseInt(e), temp[i]]);
});

演示:http://jsfiddle.net/SjL6F/1/

注意:我已经添加了parseInt,因为Highcharts要求时间戳是数字,而不是字符串。