Highcharts how to change x axis options

假装没事ソ 提交于 2019-12-22 04:37:11

问题


In Highcharts I want to change the default starting point from 0 to 1 is where can i find the option to change I have only data points so that are plotted on y axis and the x axis simply contain the default numbers ie 0,1,2, etc.. i want to change the starting point from 0 to 1

thanks in advance


回答1:


It's been a while since you've posted so I hope you've found your answer by now but I wanted to give you a response anyway.

You need to use the min option inside the X-Axis category. Read more about this here: http://api.highcharts.com/highcharts#xAxis

 xAxis: {
     min: 1,
     categories: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11']
 },

These options include the '0' as a category but the chart is drawn starting at the '1' position.

I put together a simple jsfiddle showing what you wanted to accomplish here: http://jsfiddle.net/L35DP/




回答2:


I'll do you one better. We can simply use the xAxis label formatter as a mapping function to map our index values from 0,1,...,n to 1,2,...,n+1 by defining the formatter as:

xAxis: {
    labels: {
        formatter: function() {
            return this.value + 1;
        }
    },  
}

Indeed you could define this mapping function to be anything at all. For example:

formatter: function() {
    return this.value * this.value;
}


来源:https://stackoverflow.com/questions/3947942/highcharts-how-to-change-x-axis-options

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!