【问题标题】:Cannot set min/max on highcharts with yearly series无法在具有年度系列的高图表上设置最小值/最大值
【发布时间】:2015-03-19 17:44:02
【问题描述】:

我以为我在 highcharts 方面做得更好,但现在偶然发现了一个烦人的问题,我似乎无法设置 xAxis 由年份组成的 xAxis 最小值和最大值。我在网上找不到类似的问题。

发生的情况是图表 xAxis 按预期绘制了年份……但该系列完全消失了,图表上没有 yAxis。

这就是我设置 xAxis 选项的方式……有人知道为什么会这样吗?谢谢大家的时间。

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) ]
    };

【问题讨论】:

标签: javascript json highcharts


【解决方案1】:

在您的情况下,选项 min 和 max 使用索引而不是数组的键。将2010 替换为30,将2030 替换为50,这应该可以工作!

或者使用函数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) ]
};

【讨论】:

  • 那是完美的。我需要引用索引,而不是“键”。非常感谢 R3tep。
猜你喜欢
  • 2021-06-21
  • 1970-01-01
  • 2016-04-07
  • 1970-01-01
  • 1970-01-01
  • 2012-11-04
  • 1970-01-01
  • 1970-01-01
  • 2021-05-17
相关资源
最近更新 更多