hard coder
hard coder

Reputation: 5705

Highcharts x axis shows numbers after max limit

I have a highchart (column), categories on x axis are evaluated dynamically. I have two options max and min in x-axis configuration. But when x axis categories are greater than max , it shows numbers like 13,14...etc on x-axis. I want that x-axis should show labels only for categories supplied and not pad numbers to reach up to max limit.

here is fiddle showing the problem jsfiddle

Upvotes: 0

Views: 2162

Answers (3)

Paweł Fus
Paweł Fus

Reputation: 45079

Another solution is to simply play around with formatter: http://jsfiddle.net/z1yencny/4/

        labels: {
            formatter: function(){
                var str = this.value;

                if(!isNaN(str)){ 
                     str = '';  
                }

                return str;
            }
        }

Of course, above solution won't work with numbers in categories. However, simply change condition to compare value with value under the category index.

Upvotes: 1

jlbriggs
jlbriggs

Reputation: 17791

The axis max property does not work the way you are thinking. It is not a cap value that will stop the values from going higher, it is the constant max value of the axis.

If you provide a max value, and you don't provide enough categories to reach the max, the chart fills in with the only thing it knows to do.

As mentioned in comments, you have a few options.

The most common and useful is to simply not specify a max; let your categories and data determine the max automatically.

Upvotes: 1

Kacper Madej
Kacper Madej

Reputation: 7886

If you supply chart with enough labels then they will be used instead of numbers. Example: http://jsfiddle.net/z1yencny/2/

categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug']

Upvotes: 0

Related Questions