使HighCharts轴标签以我的最小值/最大值结束

时间:2017-09-13 01:08:58

标签: javascript highcharts

为什么我的HighCharts y轴标签不会从0.5开始到17?我已经在初始化代码中明确指出了这一点,但它没有遵守它。相反,y轴标签从0开始,到18结束。

无论如何我可以控制它并强制y轴标签以我的最小值开始并以我的最大值结束(最好不需要改变我的tickAmount值)?



Highcharts.chart('container', {
    chart: {
        
    },
    yAxis: {
        min: 0.5,
        max: 17,
        //tickInterval: 10,
        tickAmount: 4,
    },

    series: [{
        data: [[5, 0.7], [10, 5]]
    }]
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>

<p>
I am expecting the y axis labels to begin at 0.5 (my min) and end at 17 (my max). Not begin at 0 and end at 20.
</p>
<div id="container" style="height: 400px"></div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

使用yAxis.tickPositioner这将起作用

Highcharts.chart('container', {
  chart: {

  },
  yAxis: {
    min: 0.5,
    max: 17,
    tickPositions: [0.5, 3, 6, 9, 12, 15, 17],

  },

  series: [{
    data: [
      [5, 0.7],
      [10, 5]
    ]
  }]
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>

<p>
  I am expecting the y axis labels to begin at 0.5 (my min) and end at 17 (my max). Not begin at 0 and end at 20.
</p>
<div id="container" style="height: 400px"></div>

答案 1 :(得分:0)

您可以将tickInterval属性设置为0.5,并使用labels.step属性容纳可见刻度数,或在tickPositions数组中指定刻度。

API参考:
http://api.highcharts.com/highcharts/yAxis.labels.step
http://api.highcharts.com/highcharts/yAxis.tickInterval
http://api.highcharts.com/highcharts/yAxis.tickPositions

示例:
http://jsfiddle.net/bfky8gce/ - 将tickInterval设置为0.5
http://jsfiddle.net/1gxp8zt7/ - 使用tickPositions