如何使用highcharts在x轴上创建中断?

时间:2015-08-29 11:07:22

标签: javascript highcharts

由于单个非常大的值,我试图在x轴上添加一个中断。 highcharts文档建议我可以像这样传递breaks

  breaks: [{
    from: 1000,
    to: 6000
  }]

但是,我的x轴仍然以相同的方式显示。我做错了什么?



$(function() {
  $('#container').highcharts({
    chart: {
      type: 'bar'
    },
    xAxis: {
      categories: ['Africa', 'America', 'Asia', 'Europe', 'Oceania'],
      breaks: [{
        from: 1000,
        to: 6000
      }]
    },
    plotOptions: {
      bar: {
        dataLabels: {
          enabled: true
        }
      }
    },
    series: [{
      name: 'Year 1800',
      data: [107, 31, 635, 203, 2]
    }, {
      name: 'Year 1900',
      data: [133, 156, 947, 408, 6]
    }, {
      name: 'Year 2012',
      data: [1052, 954, 8250, 740, 38]
    }]
  });
});

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

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/broken-axis.js"></script>

<div id="container" style="min-width: 310px; max-width: 800px; height: 400px; margin: 0 auto"></div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

在这种情况下,您希望在yAxis上休息。

yAxis: {
    breaks: [{
        from: 1000,
        to: 8000,
        breakSize: 500 // Adjust accordingly
    }]
},

http://jsfiddle.net/nicholasduffy/mh18tdpy/

http://api.highcharts.com/highcharts#yAxis.breaks.breakSize