Highchart, forcing dual yAxis to have common zero
28/07/2015
etc
Highchart is a common javascript library which use to display graph with many beautiful features, however, there is a small need in use of highchart.js. It’s about having dual yAxis, and how to balance common zero between two yAxis.
There is no built-in feature that can help you deal with this solution but changing the min, max value via setExtremes() method.
I did write a small method which can help solve this problem, small but achievable. github
How to use
- Given that, on the html there is a div which is used for highcharts, this div
is only for rendering graph for example
$("#graph")
- After include the balancezero.js, you can test by running the command on the
web console
balanceZeroRoot(dom_element)
or for examplebalanceZeroRoot($("#graph"))
- By default, there is exist behavior for
show
andhide
plots, you need to modify those default behavior to work withbalancezero.js
. For each kind of graph, there is exist option namelegendItemClick
for example link
- In addition, there is also a need to load
balanceZeroRoot()
right after data loaded. There are many kind of graph, the code below is an example aboutchart
type