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:
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?
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.
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.
If you set the chart.marginLeft option, it will override the auto size labels so the Y axes become aligned.
A little hacky way, but should work:
width
, e.g. 400pxright
, e.g. 20pxNow 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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With