How to create vertical merged stacked bar in highchart - highcharts

How to create vertical merged stacked bar in highchart.
Group Padding and Point Padding is not working in Highchart.
Expected:
Actual:
https://jsfiddle.net/sathishkumar_v/3woxcskg/
Highcharts.chart('container', {
chart: {
type: 'spline'
},
title: {
text: null
},
exporting:{
enabled: false
},
legend: {
align: 'right',
},
xAxis: {
categories: [
'6:00AM',
'7:00AM',
'8:00AM',
'9:00AM',
'10:00AM',
'11:00AM',
'12:00AM',
'1:00PM',
'2:00PM',
'3:00PM',
'4:00PM',
'5:00PM',
'6:00PM',
'7:00PM',
'8:00PM',
'9:00PM',
'10:00PM'
],
plotBands: [
{
from: 0,
to: 2,
color: '#D4E2F2'
},
{
from: 2,
to: 5,
color: '#EFC5CA'
},
{
from: 14,
to: 16,
color: '#D4E2F2'
},
{
from: 11,
to: 14,
color: '#EFC5CA'
},
]
},
yAxis: [
{
gridLineDashStyle: 'longdash',
// tickPositions: [0, 100, 200, 300, 400, 500, 600, 700, 800],
title: {
text: 'TRIPS'
}
},
{
gridLineDashStyle: 'longdash',
// tickPositions: [0, 100, 200, 300, 400, 500, 600, 700, 800],
title: {
text: 'DEMAND(PAX)'
},
opposite: true
}
],
tooltip: {
shared: true,
valueSuffix: ' units'
},
credits: {
enabled: false
},
plotOptions: {
areaspline: {
fillOpacity: 0.5
}
},
series: [{
name: 'Planned Trips',
yAxis: 1,
data: [0, 35, 80, 120, 230, 210, 175, 155, 130, 120, 150, 100, 175, 160, 175, 140, 180],
color: '#304894',
},
{
name: 'Actual Trips',
///yAxis: 2,
data: [0, 145, 165, 180, 190, 225, 195, 175, 150, 190, 200, 230, 175, 90, 115, 140, 120],
color: '#6FD1F6',
},
{
name: 'Actual Demand',
type: 'column',
stacking: 'normal',
data: [0, 25, 35, 80, 130, 150, 115, 100, 80, 70, 30, 80, 100, 75, 60, 75, 40],
color: '#6FD1F6',
pointWidth: 10
}, {
type: 'column',
name: 'Planned Demand',
stacking: 'normal',
data: [3, 35, 11, 11, 12, 14, 15, 21, 25, 25, 23, 21, 15, 13, 12, 5, 5],
color: '#304894',
pointWidth: 10
}]
});
I am using https://github.com/bellstrand/highcharts-border-radius for the border radius top - left and right

You can use a wrapper function to do this, like so:
(function (H) {
H.wrap(H.seriesTypes.column.prototype, 'drawPoints', function (proceed) {
console.log(this)
let borderRadius = this.points[0].pointWidth / 2;
this.options.borderRadius = borderRadius;
$.each(this.points, function (i,point) {
point.shapeArgs.y -= borderRadius; //move the point down by borderRadius pixels
point.shapeArgs.height += borderRadius * 2; //add borderRadius pixels to the total height of a point (to cover the gap)
});
proceed.apply(this, Array.prototype.slice.call(arguments, 1));
});
}(Highcharts));
Which takes half of the initial width of the bar as the border radius and covers the gaps they would leave.
(function (H) {
H.wrap(H.seriesTypes.column.prototype, 'drawPoints', function (proceed) {
let borderRadius = this.points[0].pointWidth / 2;
this.options.borderRadius = borderRadius;
$.each(this.points, function (i,point) {
point.shapeArgs.y -= borderRadius; //move the point down by borderRadius pixels
point.shapeArgs.height += borderRadius * 2; //add borderRadius pixels to the total height of a point (to cover the gap)
});
proceed.apply(this, Array.prototype.slice.call(arguments, 1));
});
}(Highcharts));
Highcharts.chart('container', {
chart: {
type: 'spline'
},
title: {
text: null
},
exporting:{
enabled: false
},
legend: {
align: 'right',
},
xAxis: {
categories: [
'6:00AM',
'7:00AM',
'8:00AM',
'9:00AM',
'10:00AM',
'11:00AM',
'12:00AM',
'1:00PM',
'2:00PM',
'3:00PM',
'4:00PM',
'5:00PM',
'6:00PM',
'7:00PM',
'8:00PM',
'9:00PM',
'10:00PM'
],
plotBands: [
{
from: 0,
to: 2,
color: '#D4E2F2'
},
{
from: 2,
to: 5,
color: '#EFC5CA'
},
{
from: 14,
to: 16,
color: '#D4E2F2'
},
{
from: 11,
to: 14,
color: '#EFC5CA'
},
]
},
yAxis: [
{
gridLineDashStyle: 'longdash',
// tickPositions: [0, 100, 200, 300, 400, 500, 600, 700, 800],
title: {
text: 'TRIPS'
}
},
{
gridLineDashStyle: 'longdash',
// tickPositions: [0, 100, 200, 300, 400, 500, 600, 700, 800],
title: {
text: 'DEMAND(PAX)'
},
opposite: true
}
],
tooltip: {
shared: true,
valueSuffix: ' units'
},
credits: {
enabled: false
},
plotOptions: {
areaspline: {
fillOpacity: 0.5
}
},
series: [{
name: 'Planned Trips',
yAxis: 1,
data: [0, 35, 80, 120, 230, 210, 175, 155, 130, 120, 150, 100, 175, 160, 175, 140, 180],
color: '#304894',
},
{
name: 'Actual Trips',
///yAxis: 2,
data: [0, 145, 165, 180, 190, 225, 195, 175, 150, 190, 200, 230, 175, 90, 115, 140, 120],
color: '#6FD1F6',
},
{
name: 'Actual Demand',
type: 'column',
stacking: 'normal',
data: [0, 25, 35, 80, 130, 150, 115, 100, 80, 70, 30, 80, 100, 75, 60, 75, 40],
color: '#6FD1F6',
pointWidth: 10
}, {
type: 'column',
name: 'Planned Demand',
stacking: 'normal',
data: [3, 35, 11, 11, 12, 14, 15, 21, 25, 25, 23, 21, 15, 13, 12, 5, 5],
color: '#304894',
pointWidth: 10
}]
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
Working example: https://jsfiddle.net/ewolden/3woxcskg/19/
If you have several charts in your page but only want this to affect one chart you can set a custom flag for that. You would then need to:
In the chart config:
chart: {
customFlag: 'wrap',
...
},
And in the wrapper:
(function (H) {
H.wrap(H.seriesTypes.column.prototype, 'drawPoints', function (proceed) {
console.log(this)
if(this.chart.options.chart.customFlag == 'wrap') {
let borderRadius = this.points[0].pointWidth / 2;
this.options.borderRadius = borderRadius;
$.each(this.points, function (i,point) {
point.shapeArgs.y -= borderRadius; //move the point down by borderRadius pixels
point.shapeArgs.height += borderRadius * 2; //add borderRadius pixels to the total height of a point (to cover the gap)
});
}
proceed.apply(this, Array.prototype.slice.call(arguments, 1));
});
}(Highcharts));
(function (H) {
H.wrap(H.seriesTypes.column.prototype, 'drawPoints', function (proceed) {
console.log(this)
if(this.chart.options.chart.customFlag == 'wrap') {
let borderRadius = this.points[0].pointWidth / 2;
this.options.borderRadius = borderRadius;
$.each(this.points, function (i,point) {
point.shapeArgs.y -= borderRadius; //move the point down by borderRadius pixels
point.shapeArgs.height += borderRadius * 2; //add borderRadius pixels to the total height of a point (to cover the gap)
});
}
proceed.apply(this, Array.prototype.slice.call(arguments, 1));
});
}(Highcharts));
Highcharts.chart('container', {
chart: {
type: 'spline',
customFlag: 'wrap'
},
title: {
text: null
},
exporting:{
enabled: false
},
legend: {
align: 'right',
},
xAxis: {
categories: [
'6:00AM',
'7:00AM',
'8:00AM',
'9:00AM',
'10:00AM',
'11:00AM',
'12:00AM',
'1:00PM',
'2:00PM',
'3:00PM',
'4:00PM',
'5:00PM',
'6:00PM',
'7:00PM',
'8:00PM',
'9:00PM',
'10:00PM'
],
plotBands: [
{
from: 0,
to: 2,
color: '#D4E2F2'
},
{
from: 2,
to: 5,
color: '#EFC5CA'
},
{
from: 14,
to: 16,
color: '#D4E2F2'
},
{
from: 11,
to: 14,
color: '#EFC5CA'
},
]
},
yAxis: [
{
gridLineDashStyle: 'longdash',
// tickPositions: [0, 100, 200, 300, 400, 500, 600, 700, 800],
title: {
text: 'TRIPS'
}
},
{
gridLineDashStyle: 'longdash',
// tickPositions: [0, 100, 200, 300, 400, 500, 600, 700, 800],
title: {
text: 'DEMAND(PAX)'
},
opposite: true
}
],
tooltip: {
shared: true,
valueSuffix: ' units'
},
credits: {
enabled: false
},
plotOptions: {
areaspline: {
fillOpacity: 0.5
}
},
series: [{
name: 'Planned Trips',
yAxis: 1,
data: [0, 35, 80, 120, 230, 210, 175, 155, 130, 120, 150, 100, 175, 160, 175, 140, 180],
color: '#304894',
},
{
name: 'Actual Trips',
///yAxis: 2,
data: [0, 145, 165, 180, 190, 225, 195, 175, 150, 190, 200, 230, 175, 90, 115, 140, 120],
color: '#6FD1F6',
},
{
name: 'Actual Demand',
type: 'column',
stacking: 'normal',
data: [0, 25, 35, 80, 130, 150, 115, 100, 80, 70, 30, 80, 100, 75, 60, 75, 40],
color: '#6FD1F6',
pointWidth: 10
}, {
type: 'column',
name: 'Planned Demand',
stacking: 'normal',
data: [3, 35, 11, 11, 12, 14, 15, 21, 25, 25, 23, 21, 15, 13, 12, 5, 5],
color: '#304894',
pointWidth: 10
}]
});
Highcharts.chart('container2', {
chart: {
type: 'column'
},
title: {
text: 'Monthly Average Rainfall'
},
subtitle: {
text: 'Source: WorldClimate.com'
},
xAxis: {
categories: [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
],
crosshair: true
},
yAxis: {
min: 0,
title: {
text: 'Rainfall (mm)'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: 'Tokyo',
data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}, {
name: 'New York',
data: [83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3]
}, {
name: 'London',
data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2]
}, {
name: 'Berlin',
data: [42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1]
}]
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<div id="container2" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
Working example: https://jsfiddle.net/ewolden/3woxcskg/24/

Related

Highchart Stock with combine scatter and column type series with Time format 24 hours. Not displaying 24 hours format its taking own x values

Here the bottom x axis not showing same as top x axis with each hour details when combine both line, scatter and column. Have code in JS Fiddle.
Please let me know how to resolve this issue i need to display each hour on bottom x axis.
You can see code in below link and Chart
Time Display format is not matching when combine multiple charts
Highcharts.stockChart('container', {
chart: {
animation: {
duration: 1000,
},
},
title: { text: 'Hourly Revenues for Today' },
navigator: {
xAxis: {
startOnTick: true,
endOnTick: true,
type: 'datetime',
tickAmount: 24,
tickInterval: 3600000,
min: 1656460800000,
max: 1656547199000,
}
},
xAxis: [
{
type: 'datetime',
tickAmount: 24,
tickInterval: 3600000,
startOnTick: true,
endOnTick: true,
minRange: Date.UTC(2022, 5, 29, 0, 0, 0),
maxRange: Date.UTC(2022, 5, 29, 23, 59, 59),
min: Date.UTC(2022, 5, 29, 0, 0, 0),
max: Date.UTC(2022, 5, 29, 23, 59, 59),
zoomEnabled: false
},
{
type: 'datetime',
tickAmount: 24,
tickInterval: 3600000,
minRange: Date.UTC(2022, 5, 29, 0, 0, 0),
maxRange: Date.UTC(2022, 5, 29, 23, 59, 59),
min: Date.UTC(2022, 5, 29, 0, 0, 0),
max: Date.UTC(2022, 5, 29, 23, 59, 59),
opposite: true
},
],
yAxis: {
min: 0,
title: {
text: 'Revenues in USD',
},
},
legend: {
enabled: false,
},
tooltip: {
pointFormat: 'Revenues today: <b>{point.y:,.0f} </b>',
},
credits: { enabled: false },
series: [
{
type: 'line',
name: 'Revenues today',
pointStart: Date.UTC(2022, 5, 29, 0, 0, 0),
color: 'red',
// pointWidth: 40,
data: [
{ x: Date.UTC(2022, 5, 29, 13, 4, 5), y: 23 },
{ x: Date.UTC(2022, 5, 29, 18, 4, 5), y: 20 },
],
},
{
type: 'column',
name: 'Revenues today',
getExtremesFromAll: true,
maxPointWidth: 10,
pointStart: Date.UTC(2022, 5, 29, 0, 0, 0),
// pointWidth: 40,
data: [
{ x: Date.UTC(2022, 5, 29, 22, 4, 5), y: 20 },
],
},
{
type: 'column',
name: 'Revenues today',
color: 'red',
// pointWidth: 40,
visible: false,
data: [
{ x: Date.UTC(2022, 5, 29, 0, 0, 0), y: 23 },
{ x: Date.UTC(2022, 5, 29, 23, 59, 59), y: 20 },
],
},
{
type: 'scatter',
name: 'Revenues today',
// pointWidth: 40,
data: [
{ x: Date.UTC(2022, 5, 29, 5, 4, 5), y: 23 },
{ x: Date.UTC(2022, 5, 29, 6, 4, 5), y: 20 },
],
},
],
plotOptions:{
series: {
pointStart: Date.UTC(2022, 5, 29, 0, 0, 0),
pointInterval: 3600 * 1000,
}
},
exporting: {
// we don't show the 'show data view' and 'edit in highmaps cloud' buttons
buttons: {
contextButton: {
menuItems: [
'viewFullscreen',
'printChart',
'separator',
'downloadPDF',
'downloadPNG',
'downloadJPEG',
'downloadSVG',
'separator',
'downloadXLS',
'downloadCSV',
],
},
},
},
});
The main concept for setting xAxis at the same value is to synchronize by method Highcharts.Axis#setExtremes.
function syncExtremes(e) {
var thisChart = this.chart;
if (e.trigger !== 'syncExtremes') { // Prevent feedback loop
Highcharts.each(Highcharts.charts, function(chart) {
if (chart.xAxis[0].setExtremes) { // It is null while updating
chart.xAxis[0].setExtremes(
e.min,
e.max,
undefined,
false, {
trigger: 'syncExtremes'
}
);
}
if (chart.xAxis[1].setExtremes) { // It is null while updating
chart.xAxis[1].setExtremes(
e.min,
e.max,
undefined,
false, {
trigger: 'syncExtremes'
}
);
}
});
}
}
The next step is to fire the event handler for the axis xAxis.events.setExtremes and implement inside our syncExtremes function.
xAxis: [{
type: 'datetime',
events: {
setExtremes: syncExtremes
},
}, {
type: 'datetime',
events: {
setExtremes: syncExtremes
},
opposite: true
}],
Live demo:
https://jsfiddle.net/BlackLabel/dzvou1es/3/
API References:
https://api.highcharts.com/class-reference/Highcharts.Axis#setExtremes
https://api.highcharts.com/highcharts/xAxis.events.setExtremes

Highcharts solid gauge stacked values

I have a nice gauge that displays a percentage value like so:
The options are:
{
title: false,
legend: false,
chart: {
type: 'solidgauge',
width: 150,
height: 150,
},
pane: {
size: '100%',
startAngle: 0,
background: {
backgroundColor: '#eee',
outerRadius: '100%',
innerRadius: '60%',
borderWidth: 0,
shape: 'arc',
},
},
tooltip: {
enabled: false
},
credits: {
enabled: false
},
yAxis: {
min: 0,
max: 100,
lineWidth: 0,
minorTickInterval: null,
tickPixelInterval: 400,
tickWidth: 0,
title: {
enabled: false,
},
labels: {
enabled:false
}
},
plotOptions: {
solidgauge: {
dataLabels: {
y: -15,
borderWidth: 0,
format: '{y}%',
style: {
fontSize: '1rem',
fontWeight: 'normal',
}
},
}
},
series: [{
data: [{
y: 75,
color: cyan,
}]
}]
}
But now I need two values:
I'd have expected to add some stacking option somewhere, along with something like:
series: [{
data: [{
y: 10,
color: blue,
}, {
y: 65,
color: cyan,
}]
}]
but it doesn't work. And I haven't found any example for this use-case over the internet either. :(
How can I achieve this?
There is no stacking option for soliidgague. You need to count expected values by yourself to achieve the effect from provided image:
series: [{
data: [{
y: 75,
color: 'cyan',
},
{
y: 15,
color: 'blue',
}]
}]
Demo:
https://jsfiddle.net/BlackLabel/4zq6ehfj/
As #magdalena said, unfortunately there is no stacking option in a solidgauge chart :(
I succeeded to fake this by applying the following transformation:
const absoluteValues = [{
y: 75,
color: 'cyan',
},
{
y: 15,
color: 'blue',
}];
const options = {
series: [{
name: 'My serie',
data: [].concat(absoluteValues).reduce((acc, val) => {
return [...acc, {
...val,
y: acc.reduce((result, {y}) => result + y, val.y),
}]
}, []).reverse()
}],
};
series: [
{
name: 'Operating Systems',
data: [{ y: 10, color: white, }]
size: '60%'
},
{
name: 'Browsers',
data: [{ y: 10, color: blue, }],
size: '80%',
}, {
name: 'Versions',
data: [{ y: 65, color: cyan, }],
size: '100%',
}]

Start scrollbar at the left for Highstock

I need to start the scrollbar at the left instead of the right for my Highstock graph. Any suggestions? I've seen the setExtremes options but I'm either not using it right or it doesn't do what I need. Here is the code for the graph I have so far.
$(function() {
$('#container').highcharts({
chart: {
renderTo: 'container',
defaultSeriesType: 'column'
},
title: {
text: 'Placed By Advisor'
},
xAxis: {
categories: ['John Jenkins', 'Steve Smith', 'Will Douglas', 'Dustin Johnson', 'Suzy Abbott', 'Wendy Jones'],
min: 2
},
yAxis: {
min: 0
},
legend: {
shadow: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0.5
}
},
series: [{
name: 'Unemployed',
data: [100, 100, 120, 55, 35, 189]},
{
name: 'Placed In Related',
data: [80, 108, 15, 74, 48, 88]},
{
name: 'Placed In Unrelated',
data: [17, 22, 187, 70, 75, 35]},
{
name: 'Except',
data: [10, 0, 19, 65, 25, 174]}],
scrollbar: {
enabled:true,
barBackgroundColor: 'lightgray',
//barBorderRadius: 7,
//barBorderWidth: 0,
//buttonBackgroundColor: 'gray',
//buttonBorderWidth: 0,
//buttonArrowColor: 'yellow',
//buttonBorderRadius: 0,
//rifleColor: 'yellow',
//trackBackgroundColor: 'red',
//trackBorderWidth: 1,
//trackBorderColor: 'silver',
//trackBorderRadius: 7
}
});
$('#button').click(function() {
var chart = $('#container').highcharts();
chart.xAxis[0].setExtremes(
);
});
});
Here is a fiddle of what I have so far.
You need to set min value as 0 and max as any (like 2).
http://jsfiddle.net/yHGS9/5/

Using the VU Guage: add the numeric value below needle

In the Highcharts samples, I am seeing that the speedometer has a numeric indicator below the needle pivot (http://jsfiddle.net/radi8/kbvC3/497/). I am going to use the VU gauge but would like to add this numeric indicator to this gauge view. Playing with the fiddle (http://jsfiddle.net/radi8/Z2s77/1/), I cannot seem to get this element to display.
Any suggestions?
My VU from jsFiddle
$(function () {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'gauge',
plotBorderWidth: 1,
plotBackgroundColor: {
linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
stops: [
[0, '#FFF4C6'],
[0.3, '#FFFFFF'],
[1, '#FFF4C6']
]
},
plotBackgroundImage: null,
height: 200
},
title: {
text: 'Efficiencies'
},
pane: [{
startAngle: -45,
endAngle: 45,
background: null,
center: ['25%', '145%'],
size: 300
}, {
startAngle: -45,
endAngle: 45,
background: null,
center: ['75%', '145%'],
size: 300
}],
yAxis: [{
min: 0,
max: 110,
minorTickPosition: 'outside',
tickPosition: 'outside',
labels: {
rotation: 'auto',
distance: 20
},
plotBands: [{
from: 0,
to: 70,
color: '#DF5353', // red
innerRadius: '100%',
outerRadius: '105%'
}, {
from: 70,
to: 95,
color: '#DDDF0D', // yellow
innerRadius: '100%',
outerRadius: '105%'
}, {
from: 95,
to: 110,
color: '#55BF3B', // green
innerRadius: '100%',
outerRadius: '105%'
}],
pane: 0,
title: {
text: 'OEE %<br/><span style="font-size:8px">Machine 001</span>',
y: -40
}
}, {
min: 0,
max: 110,
minorTickPosition: 'outside',
tickPosition: 'outside',
labels: {
rotation: 'auto',
distance: 20
},
plotBands: [{
from: 0,
to: 70,
color: '#DF5353', // red
innerRadius: '100%',
outerRadius: '105%'
}, {
from: 70,
to: 95,
color: '#DDDF0D', // yellow
innerRadius: '100%',
outerRadius: '105%'
}, {
from: 95,
to: 110,
color: '#55BF3B', // green
innerRadius: '100%',
outerRadius: '105%'
}],
pane: 1,
title: {
text: 'Cycle Eff %<br/><span style="font-size:8px">Machine 001</span>',
y: -40
}
}],
plotOptions: {
gauge: {
dataLabels: {
enabled: false
},
dial: {
radius: '100%'
}
}
},
series: [{
data: [80],
yAxis: 0
}, {
data: [80],
yAxis: 1
}]
},
// Let the music play
function(chart) {
setInterval(function() {
var left = chart.series[0].points[0],
right = chart.series[1].points[0],
leftVal,
//inc = (Math.random() - 0.5) * 30;
inc1 = Math.random() * (30) + 70;
inc2 = Math.random() * (30) + 70;
leftVal = left.y + inc1;
rightVal = right.y + inc2; // / 3;
if (leftVal < 0 || leftVal > 110) {
//leftVal = left.y - inc;
leftVal = 110 - inc1;
}
if (rightVal < 0 || rightVal > 110) {
rightVal = 110 - inc2;
}
left.update(leftVal,false);
right.update(rightVal);//, false);
chart.redraw();
}, 1500);
});
});
You have to enable and position dataLabels (now you have dataLabels: {enabled: false}).
See: http://api.highcharts.com/highcharts#plotOptions.gauge.dataLabels

How can you change the "label" (valueSuffix) on a highcharts gauge after the gauge has been created?

How can you change the "label" (valueSuffix) on a highcharts gauge after the gauge has been created?
something like this:
chart.series[0].remove();
chart.addSeries({
name: 'Speed',
data: [Math.random() * 200],
tooltip: {
valueSuffix: parseInt(Math.random() * 200, 16)
}
});
http://jsfiddle.net/noahpeters/d36Se/1/
Yes it is possible by using html for yAxis title. Then you can use jquery or js to change div content.
http://jsfiddle.net/d36Se/2/
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'gauge',
plotBackgroundColor: null,
plotBackgroundImage: null,
plotBorderWidth: 0,
plotShadow: false
},
title: {
text: 'Speedometer'
},
pane: {
startAngle: -150,
endAngle: 150,
background: [{
backgroundColor: {
linearGradient: {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
stops: [
[0, '#FFF'],
[1, '#333']
]
},
borderWidth: 0,
outerRadius: '109%'
}, {
backgroundColor: {
linearGradient: {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
stops: [
[0, '#333'],
[1, '#FFF']
]
},
borderWidth: 1,
outerRadius: '107%'
}, {
// default background
}, {
backgroundColor: '#DDD',
borderWidth: 0,
outerRadius: '105%',
innerRadius: '103%'
}]
},
// the value axis
yAxis: {
min: 0,
max: 200,
minorTickInterval: 'auto',
minorTickWidth: 1,
minorTickLength: 10,
minorTickPosition: 'inside',
minorTickColor: '#666',
tickPixelInterval: 30,
tickWidth: 2,
tickPosition: 'inside',
tickLength: 10,
tickColor: '#666',
labels: {
step: 2,
rotation: 'auto'
},
title: {
useHTML:true, text: '<div id="tooltipTitle">km/h</div>'
},
plotBands: [{
from: 0,
to: 120,
color: '#55BF3B' // green
}, {
from: 120,
to: 160,
color: '#DDDF0D' // yellow
}, {
from: 160,
to: 200,
color: '#DF5353' // red
}]
},
tooltip: {
formatter: function(){
return 'aaa';
}
//valueSuffix: ' km/h'
},
series: [{
name: 'Speed',
data: [80]
}]
},
// Add some life
function (chart) {
setInterval(function () {
chart.series[0].remove();
chart.addSeries({
name: 'Speed',
data: [Math.random() * 200]
});
$('#tooltipTitle').html('aaaa');
}, 3000);
});

Resources