Highcharts – Solid gauge in styled mode
author(s): Newlukai
by Anand Rathod
HTML
<script src="https://code.highcharts.com/js/highcharts.js"></script>
<script src="https://code.highcharts.com/js/highcharts-more.js"></script>
<script src="https://code.highcharts.com/js/modules/solid-gauge.js"></script>
<div style="width: 600px; height: 400px; margin: 0 auto">
<div id="container-speed" style="width: 300px; height: 200px; float: left"></div>
<div id="container-rpm" style="width: 300px; height: 200px; float: left"></div>
</div>
CSS
.highcharts-container {
position: relative;
overflow: hidden;
width: 100%;
height: 100%;
text-align: left;
line-height: normal;
z-index: 0;
/* #1072 */
-webkit-tap-highlight-color: transparent;
font-family: "Lucida Grande", "Lucida Sans Unicode", Arial, Helvetica, sans-serif;
font-size: 12px;
}
.highcharts-root text {
stroke-width: 0;
}
.highcharts-background {
fill: #ffffff;
}
.highcharts-plot-border,
.highcharts-plot-background {
fill: none;
}
.highcharts-label-box {
fill: none;
}
.highcharts-button-box {
fill: inherit;
}
/* Titles */
.highcharts-title {
fill: #333333;
font-size: 1.5em;
}
.highcharts-subtitle {
fill: #666666;
}
/* Axes */
.highcharts-axis-line {
fill: none;
stroke: #ccd6eb;
}
.highcharts-yaxis .highcharts-axis-line {
stroke-width: 0;
}
.highcharts-axis-title {
fill: #666666;
}
.highcharts-axis-labels {
fill: #666666;
cursor: default;
font-size: 0.9em;
}
.highcharts-grid-line {
fill: none;
stroke: #e6e6e6;
}
.highcharts-xaxis-grid .highcharts-grid-line {
stroke-width: 0;
}
.highcharts-tick {
stroke: #ccd6eb;
}
.highcharts-yaxis .highcharts-tick {
stroke-width: 0;
}
.highcharts-minor-grid-line {
stroke: #f2f2f2;
}
.highcharts-crosshair-thin {
stroke-width: 1px;
stroke: #cccccc;
}
.highcharts-crosshair-category {
stroke: #ccd6eb;
stroke-opacity: 1;
}
/* Credits */
.highcharts-credits {
cursor: pointer;
fill: #999999;
font-size: 0.7em;
transition: fill 250ms, font-size 250ms;
}
.highcharts-credits:hover {
fill: black;
font-size: 1em;
}
/* Tooltip */
.highcharts-tooltip {
cursor: default;
pointer-events: none;
white-space: nowrap;
transition: stroke 150ms;
}
.highcharts-tooltip text {
fill: #333333;
}
.highcharts-tooltip .highcharts-header {
font-size: 0.85em;
}
.highcharts-tooltip-box {
stroke-width: 1px;
fill: #f7f7f7;
fill-opacity: 0.85;
}
.highcharts-selection-marker {
fill: #335cad;
fill-opacity:...
JavaScript
var gaugeOptions = {
chart: {
type: 'solidgauge'
},
title: {
text: ''
},
pane: {
center: ['50%', '85%'],
size: '140%',
startAngle: -90,
endAngle: 90,
background: {
innerRadius: '60%',
outerRadius: '100%',
shape: 'arc'
}
},
tooltip: {
enabled: false
},
yAxis: {
minorTickInterval: null,
tickAmount: 2,
title: {
y: -70
},
labels: {
y: 16
}
},
plotOptions: {
solidgauge: {
dataLabels: {
y: 5,
borderWidth: 0,
useHTML: true
}
}
}
};
// The speed gauge
var chartSpeed = Highcharts.chart('container-speed', Highcharts.merge(gaugeOptions, {
yAxis: {
min: 0,
max: 200,
title: {
text: 'Speed'
}
},
credits: {
enabled: false
},
series: [{
name: 'Speed',
data: [80],
dataLabels: {
format: '<div style="text-align:center"><span style="font-size:25px;color:' +
((Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black') + '">{y}</span><br/>' +
'<span style="font-size:12px;color:silver">km/h</span></div>'
},
tooltip: {
valueSuffix: ' km/h'
}
}]
}));
// The RPM gauge
var chartRpm = Highcharts.chart('container-rpm', Highcharts.merge(gaugeOptions, {
yAxis: {
min: 0,
max: 5,
title: {
text: 'RPM'
}
},
series: [{
name: 'RPM',
data: [1],
dataLabels: {
format: '<div style="text-align:center"><span style="font-size:25px;color:' +
((Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black') + '">{y:.1f}</span><br/>' +
'<span style="font-size:12px;color:silver">* 1000 / min</span></div>'
},
tooltip: {
valueSuffix: ' revolutions/min'
}
}]
}));
// Bring life to the dials
setInterval(function() {
// Speed
var point,
newVal,
inc;
if (chartSpeed) {
point = chartSpeed.series[0].points[0];
inc = Math.round((Math.random() - 0.5) * 100);
...