Highcharts Demo
author(s): Torstein Hønsi
by Black Label
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/stock/modules/data.js"></script>
<div id="parentContainer">
<div id="container"></div>
<div id="play-controls">
<button id="play-pause-button" class="fa fa-play" title="play"></button>
<input id="play-range" type="range" value="2017" min="2017" max="2020" />
</div>
</div>
CSS
@import "https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css";
#parentContainer {
min-width: 320px;
max-width: 800px;
}
#play-controls {
position: absolute;
left: 100px;
top: 350px;
}
#play-pause-button {
width: 30px;
height: 30px;
cursor: pointer;
border: 1px solid silver;
border-radius: 3px;
background: #f8f8f8;
}
#play-range {
transform: translateY(2.5px);
}
JavaScript
var initialData,
chart;
const startYear = 2017,
endYear = 2020,
btn = document.getElementById('play-pause-button'),
input = document.getElementById('play-range');
/**
* Animate dataLabels functionality
*/
(function(H) {
const FLOAT = /^-?\d+\.?\d*$/;
// Add animated textSetter, just like fill/strokeSetters
H.Fx.prototype.textSetter = function(proceed) {
var startValue = this.start.replace(/ /g, ''),
endValue = this.end.replace(/ /g, ''),
currentValue = this.end.replace(/ /g, '');
if ((startValue || '').match(FLOAT)) {
startValue = parseInt(startValue, 10);
endValue = parseInt(endValue, 10);
// No support for float
currentValue = Highcharts.numberFormat(
Math.round(startValue + (endValue - startValue) * this.pos), 0);
}
this.elem.endText = this.end;
this.elem.attr(
this.prop,
currentValue,
null,
true
);
};
// Add textGetter, not supported at all at this moment:
H.SVGElement.prototype.textGetter = function(hash, elem) {
var ct = this.text.element.textContent || '';
return this.endText ? this.endText : ct.substring(0, ct.length / 2);
}
// Temporary change label.attr() with label.animate():
// In core it's simple change attr(...) => animate(...) for text prop
H.wrap(H.Series.prototype, 'drawDataLabels', function(proceed) {
var ret,
attr = H.SVGElement.prototype.attr,
chart = this.chart;
if (chart.sequenceTimer) {
this.points.forEach(
point => (point.dataLabels || []).forEach(
label => label.attr = function(hash, val) {
if (hash && hash.text !== undefined) {
var text = hash.text;
delete hash.text;
this.attr(hash);
console.log(text, 'text')
this.animate({
text: text
});
return this;
} else {
return attr.apply(this, arguments);
...