Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent Highcharts from truncating categories?

Tags:

highcharts

If space is too tight, the axis labels are truncated. I'm dealing with variable categories, so I'd prefer to have them overlap rather than disappear.

Example: http://jsfiddle.net/z1axtk31/

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'bar'
        },
        title: {
            text: 'Historic World Population by Region'
        },
        subtitle: {
            text: 'Source: Wikipedia.org'
        },
        xAxis: {
            categories: ['Sub-saharan Africa', 'North America', 'South America', 'East Asia', 'Middle East', 'Europe', 'Oceania', 'Ancapistan', 'North Africa', 'Mordor', 'Atlantis'],
            title: {
                text: null
            }
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Population (millions)',
                align: 'high'
            },
            labels: {
                overflow: 'justify'
            }
        },
        tooltip: {
            valueSuffix: ' millions'
        },
        plotOptions: {
            bar: {
                dataLabels: {
                    enabled: true
                }
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -40,
            y: 100,
            floating: true,
            borderWidth: 1,
            backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
            shadow: true
        },
        credits: {
            enabled: false
        },
        series: [{
            name: 'Year 1800',
            data: [107, 31, 635, 203, 2, 45, 23, 201, 50, 89, 210]
        }/*, {
            name: 'Year 1900',
            data: [133, 156, 947, 408, 6, 45, 23, 166, 50, 20, 110]
        }, {
            name: 'Year 2008',
            data: [973, 914, 4054, 732, 34, 45, 23, 20, 50, 133, 100]
        }*/]
    });
});
like image 518
nilskp Avatar asked Dec 10 '25 09:12

nilskp


1 Answers

Simply set:

xAxis: {
    labels: {
        step: 1
    }
}

Example

like image 69
Paweł Fus Avatar answered Dec 14 '25 11:12

Paweł Fus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!