JSFiddle - React, Tailwind, and code Playground
by phsiao2000
HTML
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/highcharts-more.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container"></div>
CSS
#container {
max-width: 800px;
height: 400px;
margin: 1em auto;
}
JavaScript
$(function () {
/**
* Experimental Highcharts plugin to allow download to PNG (through canvg) and SVG
* using the HTML5 download attribute.
*
* WARNING: This plugin uses the HTML5 download attribute which is not generally
* supported. See http://caniuse.com/#feat=download for current uptake.
*
* TODO:
* - Add crossbrowser support by utilizing the Downloadify Flash library?
* - Option to fall back to online export server on missing support. Display human
* readable error if not.
*/
(function (Highcharts) {
// Dummy object so we can reuse our canvas-tools.js without errors
Highcharts.CanVGRenderer = {};
/**
* Downloads a script and executes a callback when done.
* @param {String} scriptLocation
* @param {Function} callback
*/
function getScript(scriptLocation, callback) {
var head = document.getElementsByTagName('head')[0],
script = document.createElement('script');
script.type = 'text/javascript';
script.src = scriptLocation;
script.onload = callback;
head.appendChild(script);
}
/**
* Add a new method to the Chart object to invoice a local download
*/
Highcharts.Chart.prototype.exportChartLocal = function (options) {
var chart = this,
svg = this.getSVG(), // Get the SVG
canvas,
a,
href,
extension,
download = function () {
var blob;
// IE specific
if (navigator.msSaveOrOpenBlob) {
// Get PNG blob
if (extension === 'png') {
blob = canvas.msToBlob();
// Get SVG blob
} else {
blob = new...