How to get Highcharts X-Axis Categories starting a

2020-02-23 08:22发布

I have a Highcharts area chart, with string categories on the X-Axis. I want the chart to start at the left most edge of the x-axis and end at the rightmost edge, without any padding. In the image below, the red arrows show the spacing that I want to get rid of. Without text categories this is easily achievable, but with I just can't seem to figure it out. Any help appreciated, thanks.

Chart with unwanted padding

5条回答
时光不老,我们不散
2楼-- · 2020-02-23 08:28

Just add:

...
xAxis: {
  startOnTick: true,
  ...
},
...
查看更多
淡お忘
3楼-- · 2020-02-23 08:35

You can achieve the desired result by redefining labels.formatter on axis. jsFiddle is here.

But if you want to keep it simple and pass axis.categories in traditional way (I think that this is a way more better), I suggest you to use a tiny hack and redefine an Axis.init function. Try it on jsFiddle.

UPD: I've updated my previous fiddle a little. Check it out. I think that you can combine all my solution to get a nicer one.

查看更多
甜甜的少女心
4楼-- · 2020-02-23 08:42

A cleaner solution is to use the pointPlacement reference provided in the Highchart API.

Add pointPlacement: 'on' and you should be in business. (For reference, here is their example JSFiddle)

查看更多
Fickle 薄情
5楼-- · 2020-02-23 08:47

You can use spacingLeft and spacingRight to set the spacing:

chart: {
         renderTo: 'chart1',
         type: 'area',
         spacingLeft: -21,      
         spacingRight: -21,      
         spacingBottom: 1
},
查看更多
做自己的国王
6楼-- · 2020-02-23 08:54

You need the following settings.

xAxis: {           
  plotLines: [{
    value: 0, 
    color: '#color'
  }],
  tickmarkPlacement: 'on'
},
yAxis: {           
  lineWidth: 0,
}
查看更多
登录 后发表回答