2

在此处输入图像描述

我正在尝试使用 HighCharts 制作一个简单的条形图。

我想删除栏之间的空间。我的研究使我相信这些属性groundPaddingpointPadding对这个空间负责。但是将两者都设置为0并没有改变任何东西。

const config = {
      chart: {
        type: 'bar',
        spacingTop: 0,
        spacingRight: 0,
        spacingBottom: 0,
        spacingLeft: 0,
        // marginTop: 0,
        // marginRight: 0,
        // marginBottom: 0,
        // marginLeft: 0
      },
      title: {
        text: null
      },
      legend: {
        enabled: false
      },
      credits: {
        text: ''
      },
      xAxis: {
        categories: options.map(option => option.option),
        // lineWidth: 0,
        // tickWidth: 0,
      },
      yAxis: {
        title: {
          enabled: false,
        },
        gridLineWidth: 0,
        tickAmount: 0,
        showFirstLabel: false,
        showLastLabel: false
      },
      series: [{
        data: options.map(option => option.votes)
      }],
      plotOptions: {
        bar: {
          dataLabels: {
            enabled: true
          }
        },
        series: {
          pointWidth: 20,
          groundPadding: 0,
          pointPadding: 0
        }
      }
    };

有任何想法吗?

编辑:

不确定是否相关,但div我图表的红色是:

<div style={{ width: '100%', height: '100%', margin: 'auto', border: '2px solid red' }}>
    <ReactHighCharts config={config}></ReactHighCharts>
</div>

果岭div有尺寸:width: 350pxheight: 400px

演示:https ://remove-space-between-bar-hbslv6.stackblitz.io

4

2 回答 2

2

groundPadding并且pointPadding会在里面bar而不是series

plotOptions: {
  bar: {
    groupPadding: 0,
    pointPadding: 0,
    dataLabels: {
      enabled: true,
    }
  }
},

演示

于 2017-11-23T05:51:54.133 回答
1

你的代码有错误。你设置groundPadding而不是groupPadding. 另外,如果使用pointPaddingand groupPaddingpointWidth在它们之前的设置不会生效,pointWidth是根据这两个参数计算的。如果您想为所有点设置一个宽度,请仅设置pointWidth属性。至于每次添加另一个点时增加图表的高度,您可以检查加载事件的点数并使用chart.setSize函数充分更改图表大小。看看下面的例子。

API 参考:
https ://api.highcharts.com/class-reference/Highcharts.Chart.html#setSize

示例:http:
//jsfiddle.net/221k5wLh/

于 2017-11-23T17:01:59.033 回答