负值会导致错误的y轴高图

时间:2015-04-27 11:48:05

标签: highcharts

左轴的零值切换到" -80"右轴的零值切换到" -8"等等(见附图)。 我有两个y轴的以下选项:

 yAxis: [{ // Primary yAxis
        categories: ["-80","-60", "-40", "-20", "0", "20", "40", "60", "80", "100", "120", "140", "160", "180", "200"],
        tickInterval: 20,
        min: -80,
        max: 200,
        floor: -80,
        ceiling: 200,
        labels: {
            style: {
                color: Highcharts.getOptions().colors[1]
            }
        },
        title: {
            text: 'DB 1 (kr/innsatt høne)',
            style: {
                color: Highcharts.getOptions().colors[1]
            }
        },
    }, { // Secondary yAxis
        categories: ["-8","-6","-4","-2","0","2","4","6","8","10","12","14","16","18","20"],
        tickInterval: 2,
        min: -8,
        max: 20,
        floor: -8,
        ceiling: 20,
        gridLineWidth: 0,
        title: {
            text: 'Fôrpris (kr/kg fôr), Eggpris (kr/kg egg)',
            style: {
                color: Highcharts.getOptions().colors[0]
            }
        },
        labels: {
            format: '{value},0',
            style: {
                color: Highcharts.getOptions().colors[0]
            }
        },
        opposite: true,
    }],

The zero value for left axis is switched to "-80", zero value for right axis is switched to "-8"

Live demo

有人对如何解决这个问题有一些建议吗?

谢谢!

2 个答案:

答案 0 :(得分:3)

在图表选项中将alignTicks设置为false。

chart: {
        alignTicks: false
},

文档: - http://api.highcharts.com/highcharts#chart.alignTicks

答案 1 :(得分:1)

您正在将minmaxcategories结合使用。这些不会按照您期望的方式连接。

使用类别只会使用您在类别数组中包含的字符串替换该轴上的数字值01,...,因此您的值为0第一个y轴将替换为类别标签"-80"。在您的类别数组中没有索引的轴上的值将仅显示为它们自己的数值。

在您的情况下,如果您希望显示所有类别,我建议您完全删除minmax。但是,如果系列的值与这些特定的数值相关,那么您最好使用tickPositions或类似值正确地间隔刻度线,而不是使用类别。