Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highchart tick interval

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]
like image 798
HyperDevil Avatar asked Feb 03 '13 21:02

HyperDevil


People also ask

What does a tick interval of 2 mean on a chart?

A tickInterval of 2 means a tick of 0.1, 10, 1000 etc. A tickInterval of 0.2 puts a tick on 0.1, 0.2, 0.4, 0.6, 0.8, 1, 2, 4, 6, 8, 10, 20, 40 etc. If the tickInterval is too dense for labels to be drawn, Highcharts may remove ticks. If the chart has multiple axes, the alignTicks option may interfere with the tickInterval setting.

What is the tickinterval in x axis?

xAxis.tickInterval. The interval of the tick marks in axis units. When undefined, the tick interval is computed to approximately follow the tickPixelInterval on linear and datetime axes. On categorized axes, a undefined tickInterval will default to 1, one category. Note that datetime axes are based on milliseconds, so for example an interval...

Why can’t I see ticks on my chart?

If the tickInterval is too dense for labels to be drawn, Highcharts may remove ticks. If the chart has multiple axes, the alignTicks option may interfere with the tickInterval setting. Copyright © 2019, Highsoft AS. All rights reserved.

What does an undefined tick interval mean?

On categorized axes, a undefined tickInterval will default to 1, one category. Note that datetime axes are based on milliseconds, so for example an interval of one day is expressed as 24 * 3600 * 1000. On logarithmic axes, the tickInterval is based on powers, so a tickInterval of 1 means one tick on each of 0.1, 1, 10, 100 etc.


2 Answers

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.

like image 92
gert vaartjes Avatar answered Oct 08 '22 00:10

gert vaartjes


You should use tickInterval with value: 3600 * 1000

like image 24
Sebastian Bochan Avatar answered Oct 07 '22 23:10

Sebastian Bochan