如何使条形图上的xAxis与pointWidth匹配

时间:2017-12-16 11:49:50

标签: javascript css highcharts

到目前为止,我已经能够在条形图上调整pointWidth的大小,这只会改变条形图的宽度。但我真正想要的是轴也匹配那个尺寸。例如,看看这个:



Highcharts.chart('container', {
  chart: {
    type: 'bar'
  },
  xAxis: {
    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  },

  plotOptions: {
    series: {
      pointWidth: 10
    }
  },

  series: [{
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
  }]
});

<script src="https://code.highcharts.com/highcharts.js"></script>

<div id="container" style="height: 400px"></div>
&#13;
&#13;
&#13;

pointWidth表示条实际上较小,但xAxis实际上并未调整它的大小以匹配它。我该如何调整这个尺寸?

1 个答案:

答案 0 :(得分:1)

根据主容器的高度计算每个数据点容器的高度。请参阅下面示例中的320px与400px容器高度。

var opt = {
  chart: {
    type: 'bar'
  },
  xAxis: {
    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  },

  plotOptions: {
    series: {
      pointWidth: 10
    }
  },

  series: [{
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
  }]
};

Highcharts.chart('container1', opt);
Highcharts.chart('container2', opt);
<script src="https://code.highcharts.com/highcharts.js"></script>

<div id="container1" style="height: 320px"></div>
<div id="container2" style="height: 400px"></div>