Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum bar width in Highcharts column charts

Tags:

I'm using Highcharts to create some vertical bars (a.k.a. "column charts") a lot like here: highcharts.com/demo/column-basic

Thing is, sometimes there are 30 bars in the chart, sometimes only two. Where then are two really wide bars in the chart, it looks really weird, so the decision was made to set a maximum width for the bars. That way if there are only two then they wouldn't get wider than, say, 50px, but if there were 50 then Highcharts could size them in the way it sees fit.

So my problem is that Highcharts doesn't have a way to explicitly set the maximum width of the columns. Has anyone found a solution to that?

like image 979
rusty Avatar asked May 11 '11 18:05

rusty


People also ask

How do I change the width of a Highchart?

Wrap your charts in a container and this will give you the flexibility to adjust the chart size when your screen changes. Also provide a width to your wrapper and make it float to the left so that charts are placed side by side.

How do I reduce the gap between bars in Highcharts?

Re: Reducing the space between the bars (column range) You can for example lower the max property value (or change extremes with Axis. setExtremes()) to reduce the visible range and this way you can retain fixed pointWidth and increase space between tick at the same time.


1 Answers

Obviously this question was asked a long time ago when this feature didn't exist, but as of Highcharts 4.1.8 you can do this without any workarounds using the plotOptions.column.maxPointWidth setting:

$('#container').highcharts({     /* Other chart settings here... */     plotOptions: {         column: {             /* Here is the setting to limit the maximum column width. */             maxPointWidth: 50         }     }     /* Other chart settings here... */ }); 

Below is the JSFiddle of the basic column chart example, modified to show this working:

http://jsfiddle.net/vu3dubhb/

And the documentation for this setting is here: http://api.highcharts.com/highcharts#plotOptions.column.maxPointWidth

like image 70
Adam Goodwin Avatar answered Oct 09 '22 18:10

Adam Goodwin