Highcharts条形图强制条使用空间

时间:2017-04-27 19:34:34

标签: highcharts

我需要将一些高图条形图放入狭小的空间。因此,我指定yAxis的最大值与最大条的值相同。在某些情况下,这会导致栏使用图表上的所有可用空间。在其他情况下,它没有。如何让它始终使用所有可用空间?在下面的jsfiddle中,我将max设置为13(数据中的max也是13)。如果更改为4,则栏使用所有空格。

这是最大值:

"yAxis": {
  "min": 0,
  "max": 13,

和数据:

"data": [0, 0, 1, 13, 0, 0, 0]

http://jsfiddle.net/MichaelWitt/2ksq39g3/2/

这是差距: enter image description here

当我将相关值设置为4时,我没有得到这个差距:enter image description here

1 个答案:

答案 0 :(得分:2)

在yAxis选项中添加"endOnTick": false,。有关详细信息,请参阅here

Highcharts.chart('container', {
  "global": {
    "useUTC": false,
    "timezoneOffset": -5
  },
  "chart": {
    "type": "bar",
    "height": 200,
    "marginLeft": 110,
    "marginRight": 0,
    "spacingLeft": 0,
    "spacingRight": 0,
    "style": {
      "fontFamily": "Arial",
      "fontSize": 14
    }
  },
  "tooltip": {
    "enabled": false
  },
  "exporting": {
    "enabled": false
  },
  "title": {
    "text": "",
    "style": {
      "display": "none"
    }
  },
  "subtitle": {
    "text": "",
    "style": {
      "display": "none"
    }
  },
  "legend": {
    "enabled": false
  },
  "xAxis": {
    "categories": ["x", "y", "z", "a", "b", "c", "d"],
    "labels": {
      "style": {
        "fontFamily": "Arial",
        "fontSize": "14px"
      }
    },
    "title": {
      "text": null
    },
    "minorTickLength": 0,
    "tickLength": 0
  },
  "yAxis": {
    "min": 0,
    "max": 13,
    "labels": {
      //"enabled": false  /*un comment this*/
    },
    "gridLineWidth": 0,
    "minorTickLength": 0,
    "tickLength": 0,
    "endOnTick": false, /*added*/
    "title": {
      "text": null
    }
  },
  "plotOptions": {
    "bar": {
      "dataLabels": {
        "enabled": false,
        "align": "left",
        "inside": true,
        "style": {
          "color": "white",
          "fontSize": "12px",
          "fontFamily": "Arial",
          "textShadow": false
        },
        "shadow": false
      }
    }
  },
  "credits": {
    "enabled": false
  },
  "series": [{
    "pointWidth": 22,
    "name": "Medium",
    "color": "#FFC627",
    "data": [0, 0, 1, 13, 0, 0, 0]
  }]
});
<script src="https://code.highcharts.com/highcharts.js"></script>

<div id="container" style="height: 400px"></div>