Highcharts zero-align y-axes
by J. Albert Bowden
HTML
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highcharts/4.1.7/highcharts.js"></script>
<script src="https://dl.dropboxusercontent.com/u/35343319/tick_positioner.js"></script>
<body>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
</body>
JavaScript
$(function () {
$('#container').highcharts({
chart: {
zoomType: 'xy'
},
title: {
text: 'Example 2 - Extended'
},
xAxis: [{
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
crosshair: true
}],
yAxis: [{ // Primary yAxis
labels: {
format: '{value}°C',
style: {
color: Highcharts.getOptions().colors[0]
}
},
title: {
text: 'Foo',
style: {
color: Highcharts.getOptions().colors[0]
}
}
}, { // Secondary yAxis
title: {
text: 'Bar',
style: {
color: Highcharts.getOptions().colors[1]
}
},
labels: {
format: '{value} mm',
style: {
color: Highcharts.getOptions().colors[1]
}
},
opposite: true
}],
tooltip: {
shared: true
},
legend: {
layout: 'vertical',
align: 'left',
x: 120,
verticalAlign: 'top',
y: 100,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
},
series: [{
name: 'Foo',
type: 'column',
data: [5, 10, 15, 20, 25, 30, 35, -40, -45, -50, -55, -60],
tooltip: {
valueSuffix: '°C'
}
},
{
name: 'Bar',
type: 'column',
yAxis: 1,
data: [-10, -20, -30, -20, -10, -20, -30, 20, 10, 20, 30, 20],
tooltip: {
valueSuffix: ' mm'
}
}]
});
});