Highcharts test tool
by Torstein Hønsi
HTML
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container"></div>
CSS
#container {
width: 100%;
height: 300px;
margin: 1em auto;
}
JavaScript
(function (H) {
// Local variables in exporting.src.js
var win = window,
doc = document,
each = H.each,
fireEvent = HighchartsAdapter.fireEvent;
/**
* Print the chart
*/
Highcharts.Chart.prototype.print = function () {
var chart = this,
container = chart.container,
origDisplay = [],
origParent = container.parentNode,
body = doc.body,
childNodes = body.childNodes;
if (chart.isPrinting) { // block the button while in printing mode
return;
}
fireEvent(chart, 'startPrint', undefined, function () {
chart.isPrinting = true;
// hide all body content
each(childNodes, function (node, i) {
if (node.nodeType === 1) {
origDisplay[i] = node.style.display;
node.style.display = 'none';
}
});
// pull out the chart
body.appendChild(container);
// print
win.focus(); // #1510
win.print();
// allow the browser to prepare before reverting
setTimeout(function () {
// put the chart back in
origParent.appendChild(container);
// restore all body content
each(childNodes, function (node, i) {
if (node.nodeType === 1) {
node.style.display = origDisplay[i];
}
});
chart.isPrinting = false;
fireEvent(chart, 'endPrint');
}, 1000);
});
};
}(Highcharts));
$('#container').highcharts({
chart: {
events: {
startPrint: function () {
...