Highcharts Demo
author(s):
Torstein Hønsi
by Santosh Giridhara
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/xrange.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container"></div>
CSS
@import 'https://code.highcharts.com/css/highcharts.css';
#container {
min-width: 300px;
max-width: 800px;
height: 300px;
margin: 1em auto;
}
.highcharts-xrange-series .highcharts-point {
stroke-width: 1px;
stroke: gray;
}
.highcharts-partfill-overlay {
fill: #010101;
fill-opacity: 0.3;
}
.highcharts-data-label text {
fill: white;
text-shadow: 1px 1px black, -1px 1px black, -1px -1px black, 1px -1px black;
}
JavaScript
Highcharts.chart('container', {
chart: {
type: 'xrange',
styledMode: true,
events: {
render: function() {
var chart = this,
offsetTop = -8,
offsetLetf = 5,
x1,
x2,
y,
label1,
label2,
label2BBox;
if (chart.customLabels && chart.customLabels.length) {
chart.customLabels.forEach(function(label) {
label.destroy();
});
}
chart.customLabels = [];
chart.series[0].points.forEach(function(point) {
x1 = point.plotX + chart.plotLeft + offsetLetf;
x2 = x1 + point.shapeArgs.width - 2 * offsetLetf;
y = point.plotY + chart.plotTop + point.shapeArgs.height / 2 + offsetTop;
label1 = chart.renderer.text(chart.xAxis[0].dataMin, x1, y).css({
fill: '#fff'
}).add().toFront();
label2 = chart.renderer.text(chart.xAxis[0].dataMax, x2, y).css({
fill: '#fff'
}).add().toFront();
label2BBox = label2.getBBox();
label2.translate(-label2BBox.width, 0);
chart.customLabels.push(label1);
chart.customLabels.push(label2);
});
}
}
},
title: {
text: ''
},
credits: {
enabled: false
},
exporting: {
enabled: false
},
xAxis: {
type: 'linear',
visible: false
},
yAxis: {
title: {
text: ''
},
reversed: true,
visible: false
},
plotOptions: {
series: {
dataLabels: {
formatter: function() {
var point = this.point;
return point.partialFill * point.x2;
}
}
}
},
series: [{
showInLegend: false,
pointWidth: 25,
data: [{
x: 0,
x2: 150,
y: 0,
partialFill: 0.75
}],
dataLabels: {
enabled: true
}
}]
});