Highcharts remove space before first bar and after last

为君一笑 提交于 2019-12-12 00:39:38

问题


I'm trying to remove the space at the top and bottom of this chart http://jsfiddle.net/bfa1o0ar/7/ . It's the spacing just before the first bar and after the last bar. I've tried removing padding, margins etc.

$(function() {
  Highcharts.chart('container', {
    chart: {
        marginTop: 0,
      marginBottom: 0,
      spacingTop: 0,
      spacingBottom: 0,
      type: 'bar',
      title: {
        text: ''
      }
    },
    credits: {
      enabled: false
    },
    title: {
      text: null
    },
    xAxis: {
      minPadding:0,
      maxPadding:0,
        lineWidth: 0,
        gridLineWidth: 0,
      tickWidth: 0,
      tickAmount: 0,
      tickmarkPlacement: 'on',
      categories: ['1-3', '4-7', '7-10', '11-14', '15-20'],
      allowDecimals: false,
    },
    yAxis: {
      minPadding:0,
      maxPadding:0,
        lineWidth: 0,
        gridLineWidth: 0,
      endOnTick: false,
      showFirstLabel: false,
      showLastLabel: false,
      startOnTick: false,
      tickWidth: 0,
      tickAmount: 0,
      //tickmarkPlacement: 'between',
      min: 0,
      allowDecimals: false,
      title: {
        text: ''
      },
      stackLabels: {
        enabled: true,
        style: {
          fontWeight: 'bold',
          color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
        }
      }
    },
    legend: {
      enabled: false
    },
    plotOptions: {
      column: {
        groupPadding: 0,
        pointPadding: 0,
        //pointWidth: 35, // width of bar
        pointRange: 0
      },
      series: {
        pointPadding: 0.1,
        groupPadding: 0,
        borderWidth: 0,
        //pointWidth: 30,
        shadow: false,
        stacking: 'normal',
        dataLabels: {
          align: 'right',
          enabled: false,
          color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
        },
      }
    },
    series: [{
      name: 'John',
      data: [5, 3, 4, 7, 2]
    }]
  });
});

回答1:


Set min/max of the x axis to first category index + 0.1 and last category index - 0.1

  min: 0 + 0.1,
  max: 4 - 0.1
},

example: http://jsfiddle.net/bfa1o0ar/8/



来源:https://stackoverflow.com/questions/41324956/highcharts-remove-space-before-first-bar-and-after-last

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!