Highchart tick interval
Asked Answered
E

2

5

I cannot seem to figure out how to set my tick interval correctly.
Need to have an hourly tick on the X axis.
The data is minute based.

Javascript:

$(function () {
    var chart;
    $(document).ready(function() {
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                type: 'spline'
            },
            title: {
                text: 'Temperature Today'
            },
            xAxis: {
                type: "datetime",
                categories: time,
                dateTimeLabelFormats: {
                    day: '%h'
                },
                minTickInterval: 24 * 36000000 * 1000,
            },
            yAxis: {
                title: {
                    text: 'Temperature'
                },
                minorGridLineWidth: 0,
                gridLineWidth: 0,
                alternateGridColor: null
            },
            tooltip: {
                formatter: function() {
                        return ''+
                        Highcharts.dateFormat('%e. %b %Y, %H:00', this.x) +': '+ this.y;
                }
            },
            plotOptions: {
                spline: {
                    lineWidth: 4,
                    states: {
                        hover: {
                            lineWidth: 5
                        }
                    },
                    marker: {
                        enabled: false,
                        states: {
                            hover: {
                                enabled: true,
                                symbol: 'circle',
                                radius: 5,
                                lineWidth: 1
                            }
                        }
                    },
                }
            },
            series: [{
                name: 'Asen',
                data: temp
            }]
            ,
            navigation: {
                menuItemStyle: {
                    fontSize: '6px'
                }
            }
        });
    });

});

Data arrays:

temp = [-4.39,-4.39,-4.33,-4.33,-4.33,-4.33,-4.33]
time = [1359910725000,1359910786000,1359910848000,1359910908000,1359910968000,1359911028000,1359911089000,1359911150000]
Eighteenmo answered 3/2, 2013 at 21:38 Comment(2)
see #11470933Featureless
Tried that, still does not work: tickInterval: 24 * 3600000 * 1000 and set dateTimeLabelFormats: to %H %MEighteenmo
E
16

First of all, remove the 'categories' property on xAxis, this has no meaning on a datetime axis. Note that datetime axes are based on milliseconds, so an interval of one hour is expressed as 3600 * 1000. See API highcharts, tickInterval

use this config for the xAxis.

xAxis: {
        type: "datetime",    
        dateTimeLabelFormats: {
            day: '%H'
        },
        tickInterval: 3600 * 1000
}, 

See here for a working demo on JS Bin.

Excitable answered 4/2, 2013 at 8:38 Comment(1)
I had to change %H to %H:%M to make 00 to 00:00Eighteenmo
D
3

You should use tickInterval with value: 3600 * 1000

Dann answered 4/2, 2013 at 8:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.