NoOneElse
NoOneElse

Reputation: 1251

fix a number of labeles on xAxis highcharts

i'm using highcharts to display prices variation throw an ajax request

http://jsfiddle.net/5wERK/ (i changed the code to work for you :) )

var options = {
        chart: {
            renderTo: 'container',
            type: 'line',
            height: 80,
            width: 190,
            backgroundColor: '#EBEEEF'
        },
        title: {
            text: ''
        },
        xAxis: {
            type: 'datetime',
            labels: {
                style: {
                    fontSize: '9px'
                }
            }
        },
        yAxis: {

            title: {
                text: ''
            },
            labels: {
                style: {
                    fontSize: '9px'
                }
            }
        },
        plotOptions: {
            series: {
                marker: {
                    enabled: false
                }
            }
        },
        legend: {
            enabled: false
        },
        credits: {
            enabled: false
        },
        tooltip: {
            followPointer: true,
            formatter: function () {
                var p = Highcharts.numberFormat(this.y, 2, ',', ' ')
                var d = Highcharts.dateFormat('%d/%m/%Y', this.x)
                return d + '<br>' + p + ' €';
            }
        },
        series: [{
                color: '#646D70',
                data: [[1360598402000,299.99],[1360836003000,297.99],[1361037604000,309.99],[1361210401000,307.99],[1362470402000,308.22],[1362643202000,309.99],[1362762002000,308.22],[1363075202000,307.23],[1363248003000,308.99],[1363334402000,307.23],[1363366802000,312.19],[1363766402000,313.99],[1363798802000,309.99],[1363849202000,369.99],[1364025602000,299.99],[1364198402000,369.99],[1364241602000,455.00],[1364562003000,347.24],[1365145202000,337.38],[1365663602000,325.99],[1366387202000,337.00],[1366441202000,332.45],[1366700402000,381.75],[1367074803000,332.45],[1367229602000,381.75],[1367301602000,341.00],[1367388002000,346.00],[1367672402000,341.00]]
            }
        ]
    };
chart = new Highcharts.Chart(options);

in the given example a have 2 labels on the xAxis i would like to display 4, is there a solution ?

thanks

Upvotes: 0

Views: 4058

Answers (2)

Sebastian Bochan
Sebastian Bochan

Reputation: 37578

You should set tickInverval, which allows to define distance between ticks. http://api.highcharts.com/highcharts#xAxis.tickInterval

Upvotes: 0

haejeong87
haejeong87

Reputation: 957

You can use tickPixelInterval to increase number of labels. To display 4, however, I think you also need to increase the width of the chart itself.

http://jsfiddle.net/5wERK/4/

    var options = {
        xAxis: {
            tickPixelInterval: 50,
        }
    }

Upvotes: 1

Related Questions