javascript - Maximum bar width in Highcharts column charts -


i'm using highcharts create vertical bars (a.k.a. "column charts") lot here: highcharts.com/demo/column-basic

thing is, there 30 bars in chart, two. 2 wide bars in chart, looks weird, decision made set maximum width bars. way if there 2 wouldn't wider than, say, 50px, if there 50 highcharts size them in way sees fit.

so problem highcharts doesn't have way explicitly set maximum width of columns. has found solution that?

update: of highcharts version 4.1.8 , see adam goodwin's answer, below.



for many years, way set maximum width of columns, dynamically via javascript.

basically:

  1. check current bar width.
  2. if greater desired, reset series' pointwidth.
  3. force redraw make change visible.

something like:

var chart = new highcharts.chart ( { ... ...  //--- enforce maximum bar width. var maximumbarwidth = 40; //-- pixels. var series          = chart.series[0];  if (series.data.length) {      if (series.data[0].barw  >  maximumbarwidth) {         series.options.pointwidth = maximumbarwidth;         /*--- force redraw.  note redraw() not              fire in case!             hence use setsize().         */         chart.setsize (400, 300);        } } 


see demo @ jsfiddle.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -