简体   繁体   English

无法按年度系列在高图上设置最小/最大

[英]Cannot set min/max on highcharts with yearly series

I thought I was getting better at highcharts but have now stumbled on an annoying issue, where I cannot seem to be able to set the xAxis min and max values where the xAxis is composed of years. 我以为自己在高级图表上会变得更好,但是现在偶然发现了一个令人讨厌的问题,在该问题上,我似乎无法设置xAxis的最小值和最大值(其中xAxis由年份组成)。 I cannot find a similar issue online. 我在网上找不到类似的问题。

What happens is the chart xAxis plots the years as expected ... but the series simply vanish and there is no yAxis on the chart. 发生的是图表xAxis按预期方式绘制了年份...但是该系列只是消失了,图表上没有yAxis。

This is how I have set up my xAxis options ... Has anybody got any idea as to why this is going on? 这就是我设置xAxis选项的方式。有人知道为什么会这样吗? Thank you all for your time. 谢谢大家的时间。

xAxis: {
        min: 2010,
        max: 2030,
        categories: [1980,  1981,   1982,   1983,   1984,   1985,   1986,   1987,   1988,   1989,   1990,   1991,   1992,   1993,   1994,   1995,   1996,   1997,   1998,   1999,   2000,   2001,   2002,   2003,   2004,   2005,   2006,   2007,   2008,   2009,   2010,   2011,   2012,   2013,   2014,   2015,   2016,   2017,   2018,   2019,   2020,   2021,   2022,   2023,   2024,   2025,   2026,   2027,   2028,   2029,   2030,   2031,   2032,   2033,   2034,   2035,   2036,   2037,   2038,   2039,   2040]
        },
        series: [ (I have removed them from the example) ]
    };

In your case, the options min & max use the index and not the key of your array. 在您的情况下,选项minmax使用索引而不是数组的键。 Replace 2010 by 30 and 2030 by 50 , this should be working! 2010替换为30 ,将2030替换为50 ,这应该可以正常工作!

Or use the function indexOf : 或使用函数indexOf

var yourArray = [1980,  1981,   1982,   1983,   1984,   1985,   1986,   1987,   1988,   1989,   1990,   1991,   1992,   1993,   1994,   1995,   1996,   1997,   1998,   1999,   2000,   2001,   2002,   2003,   2004,   2005,   2006,   2007,   2008,   2009,   2010,   2011,   2012,   2013,   2014,   2015,   2016,   2017,   2018,   2019,   2020,   2021,   2022,   2023,   2024,   2025,   2026,   2027,   2028,   2029,   2030,   2031,   2032,   2033,   2034,   2035,   2036,   2037,   2038,   2039,   2040]

.
. //Define your highcharts options
.

    xAxis: {
        min: yourArray.indexOf(2010),
        max: yourArray.indexOf(2030),
        categories: yourArray
    },
    series: [ (I have removed them from the example) ]
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM