Gauge with dual axes
author(s):
Torstein Hønsi
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.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>
<figure class="highcharts-figure">
<div id="container"></div>
<p class="highcharts-description">
Chart showing multiple axes with a gauge series. The axes are positioned
to display an outer and inner axis. The chart is dynamically updated
every few seconds with a new value.
</p>
</figure>
CSS
body {
font-family:
-apple-system,
BlinkMacSystemFont,
"Segoe UI",
Roboto,
Helvetica,
Arial,
"Apple Color Emoji",
"Segoe UI Emoji",
"Segoe UI Symbol",
sans-serif;
background: var(--highcharts-background-color);
color: var(--highcharts-neutral-color-100);
}
#container {
height: 400px;
}
.highcharts-figure,
.highcharts-data-table table {
min-width: 310px;
max-width: 500px;
margin: 1em auto;
}
.highcharts-data-table table {
font-family: Verdana, sans-serif;
border-collapse: collapse;
border: 1px solid var(--highcharts-neutral-color-10, #e6e6e6);
margin: 10px auto;
text-align: center;
width: 100%;
max-width: 500px;
}
.highcharts-data-table caption {
padding: 1em 0;
font-size: 1.2em;
color: var(--highcharts-neutral-color-60, #666);
}
.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 tbody tr:nth-child(even) {
background: var(--highcharts-neutral-color-3, #f7f7f7);
}
.highcharts-description {
background: light-dark(#f2f6f2, #323232);
border-radius: 0 4px 4px 0;
border-left: 2px solid light-dark(#1d6aff, #fff);
font-size: 0.8rem;
font-style: italic;
padding: 8px 16px;
margin: 2em 10px 1em;
}
JavaScript
Highcharts.chart('container', {
chart: {
type: 'gauge',
alignTicks: false,
plotBackgroundColor: null,
plotBackgroundImage: null,
plotBorderWidth: 0,
plotShadow: false
},
title: {
text: 'Speedometer with dual axes'
},
pane: {
startAngle: -150,
endAngle: 150,
background: [{
outerRadius: '105%',
innerRadius: 0,
shape: 'circle'
}]
},
yAxis: [{
min: 0,
max: 200,
lineColor: '#2caffe',
tickColor: '#2caffe',
minorTicks: true,
minorTickColor: '#2caffe',
minorTickWidth: 1,
minorTickPosition: 'inside',
tickWidth: 2,
offset: -25,
lineWidth: 2,
labels: {
distance: -45,
rotation: 'auto'
},
tickLength: 5,
minorTickLength: 5,
endOnTick: false
}, {
min: 0,
max: 124,
tickPosition: 'outside',
lineColor: '#d66',
lineWidth: 2,
minorTicks: true,
minorTickLength: 5,
minorTickColor: '#d66',
minorTickWidth: 1,
tickColor: '#d66',
tickWidth: 2,
tickLength: 5,
labels: {
distance: -8,
rotation: 'auto'
},
offset: -20,
endOnTick: false
}],
series: [{
name: 'Speed',
data: [80],
dataLabels: {
format: '<span style="color:#2caffe">{y} km/h</span><br/>' +
'<span style="color:#d66">{(multiply y 0.621):.0f} mph</span>',
style: {
textOutline: 'none',
fontSize: '1.2em'
}
},
tooltip: {
valueSuffix: ' km/h'
}
}]
},
// Add some life
function (chart) {
setInterval(function () {
if (chart.axes) { // not destroyed
const point = chart.series[0].points[0],
inc...