yaochiqkl
yaochiqkl

Reputation: 489

In HighCharts how to set number of xAxis autoly?

As you can see , I'm using HighStock of HighCharts now in order to have scroll bar.
I want to set max number of xAxis. It works if I code like this:

xAxis: {
    max: 8
    categories: data.categories
}  

Here is the rendering: normal one  But when it concern to some data that hasn't so many xAxis data , it will show like this : Bad one
What I want to realize is that when the data is less than a certain number,for example, 8, It will occupy the chart instead of leaving so many blank.
Here is the pic:
My target

Upvotes: 0

Views: 58

Answers (1)

Sebastian Bochan
Sebastian Bochan

Reputation: 37588

The solution is check if categories array is bigger than 8, if not then set maximum value as categories length

xAxis: {
        max: categories.length < 8 ? categories.length - 1: 8,
        categories: categories
    },

Example:

Upvotes: 1

Related Questions