Azfar Kashif
Azfar Kashif

Reputation: 193

X-axis interval in Highcharts

My highcharts graph

I have this highchart graph displayed on my website. How can I set an interval for my x-axis? e.g. I want the fist value to be displayed and then skip the second and display the third. Can this be done? Or do you always just HAVE to display all the data you're passing to the axis in an array?

My code: (timestamp is a JS array that contains my time. I can get that time in epoch format. act and temps are arrays for data to be plotted along y-axis)

$(function () {
    $('#tempactgraph').highcharts({
        chart: {
            zoomType: 'xy'
        },
        title: {
            text: 'Temperature & Activity Monitoring '
        },
        subtitle: {
            text: 'Source: Cowlar Sensors'
        },
        xAxis: [{
            categories: timestamp,
            crosshair: true
        }],
        yAxis: [{ // Primary yAxis
            labels: {
                format: '{value}°C',
                style: {
                    color: Highcharts.getOptions().colors[1]
                }
            },
            title: {
                text: 'Temperature',
                style: {
                    color: Highcharts.getOptions().colors[1]
                }
            }
        }, { // Secondary yAxis
            title: {
                text: 'Activity',
                style: {
                    color: Highcharts.getOptions().colors[0]
                }
            },
            labels: {
                format: '{value} xx',
                style: {
                    color: Highcharts.getOptions().colors[0]
                }
            },
            opposite: true
        }],
        tooltip: {
            shared: true
        },
        legend: {
            layout: 'vertical',
            align: 'left',
            x: 120,
            verticalAlign: 'top',
            y: 100,
            floating: true,
            backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
        },
        series: [{
            name: 'Activities',
            type: 'spline',
        connectNulls: 1,
            yAxis: 1,
            data: act,
            tooltip: {
                valueSuffix: ' xx'
            }

        }, {
            name: 'Temperature',
            type: 'spline',
        connectNulls: 1,
            data: temps,
            tooltip: {
                valueSuffix: '°C'
            }
        }]
    });
});

Upvotes: 0

Views: 8160

Answers (1)

Simon West
Simon West

Reputation: 3778

You need to Add a tickInterval:2 to your x-axis decleration like so

xAxis: [{
            categories: timestamp,
            crosshair: true,
            tickInterval: 2
        }],

Highcharts API Reference

Upvotes: 2

Related Questions