Line chart with multiple y-axes

author(s): Øystein Moseng

by oysteinmoseng

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<script src="https://code.highcharts.com/themes/high-contrast-light.js"></script>

<h1>Line chart with two y-axes</h1>
<h2>Chart</h2>
<figure class="highcharts-figure">
    <div id="container"></div>
    <p class="highcharts-description">
        Time series line chart with two y-axes. The price line is showing a complex downwards trend.
    </p>
</figure>
<h2>CSV data</h2>
<p>
    Source: <a href="https://finance.yahoo.com/quote/ALK?p=ALK">Yahoo Finance</a>
</p>
<pre...

CSS

body {
  font-family: Verdana, sans-serif;
  padding-left: 10px;
}

p {
    margin-left: 1rem;
}

h2 {
  font-size: 1.3rem;
  margin-left: 10px;
  margin-bottom: 0;
  margin-top: 1.5rem;
}

pre {
  margin-left: 1rem;
  border: 1px solid #cde;
  max-width: 600px;
  padding: 10px;
  background-color: #f9f9f9;
  border-radius: 10px;
}

#container {
    height: 600px;
}

.highcharts-figure, .highcharts-data-table table {
    min-width: 320px;
    max-width: 700px;
    margin: 1em;
}

.highcharts-data-table table {
	font-family: Verdana, sans-serif;
	border-collapse: collapse;
	border: 1px solid #EBEBEB;
	margin: 10px auto;
	text-align: center;
	width: 100%;
	max-width: 500px;
}
.highcharts-data-table caption {
    padding: 1em 0;
    font-size: 1.2em;
    color: #555;
}
.highcharts-data-table th {
	font-weight: 600;
    padding: 0.5em;
}
.highcharts-data-table td, .highcharts-data-table th, .highcharts-data-table caption {
    padding: 0.5em;
}
.highcharts-data-table thead tr, .highcharts-data-table tr:nth-child(even) {
    background: #f8f8f8;
}
.highcharts-data-table tr:hover {
    background: #f1f7ff;
}


input[type="number"] {
	min-width: 50px;
}

JavaScript

var chart = Highcharts.chart('container', {
    chart: {
        type: 'line'
    },
    title: {
        text: 'Alaska Air Group, 5yr stock prices'
    },
    subtitle: {
	    text: 'Source: <a href="https://finance.yahoo.com/quote/ALK?p=ALK">Yahoo Finance</a>'
    },
    tooltip: {
        stickOnContact: true
    },
    xAxis: {
    	type: 'datetime'
    },
    legend: {
    	enabled: false
    },
    yAxis: [{
    	title: {
        	text: 'Price'
        },
        height: '70%'
    }, {
    	title: {
        	text: 'Volume'
        },
    	opposite: true,
        height: '30%',
        top: '70%'
    }],
    data: {
    	csv: document.getElementById('csv').innerHTML
    },
    series: [{
    }, {
    	yAxis: 1,
        type: 'area'
    }]
});