Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixed y-axis label width in Highcharts

Tags:

highcharts

I'm building a data presentation where two Highcharts charts are stacked vertically and are intended to share the same x-axis units and alignment. Like so:

Stacked Highcharts

Notice that since the y-axis ranges are different for the two charts, the y-axis labels are different widths and thus the charts themselves are slightly different widths breaking the nice x-axis alignment.

It would be great to be able to fix the width of the chart (or conversely the y-axis labels) to ensure the two charts line up. I explored the api and played a bit with setting styling directly on the various generated elements but no luck. It seems possible to maybe achieve this goal using a custom label formatter, but the stock formatter (as in if I define nothing custom) works quite well for abbreviating large numbers and such.

Ideas as to how to fix the chart or y-axis label width?

like image 461
qfinder Avatar asked Mar 23 '13 01:03

qfinder


People also ask

Is the Y axis the width?

The x-axis and y-axis represent the first two dimensions; the z-axis, the third dimension. In a graphic image, the x and y denote width and height; the z denotes depth.

What is the label of the y axis?

In a chart you create, axis labels are shown below the horizontal (category, or "X") axis, next to the vertical (value, or "Y") axis, and next to the depth axis (in a 3-D chart). Your chart uses text from its source data for these axis labels.


3 Answers

If you set the chart.marginLeft option, it will override the auto size labels so the Y axes become aligned.

like image 97
Torstein Hønsi Avatar answered Oct 10 '22 05:10

Torstein Hønsi


A little hacky way, but should work:

  • set for both xAxis width, e.g. 400px
  • set for all axis (xAxis and yAxis) right, e.g. 20px

Now yAxis should have the same width and also the same extremes etc.

Another (and maybe even better) solution is to use two panes for Highcharts. It works exactly the same way as in Highstock, see example: http://www.highcharts.com/stock/demo/candlestick-and-volume

like image 30
Paweł Fus Avatar answered Oct 10 '22 06:10

Paweł Fus


This is a late answer, but you can now do multiple charts inside the same Highcharts object. You wouldn't have to manually try to force the Y axes to align when using this method, as Highcharts would do all the work for you.

http://www.highcharts.com/demo/combo

like image 32
fotijr Avatar answered Oct 10 '22 04:10

fotijr