JSFiddle - React, Tailwind, and code Playground
Examples of using Highcharts Export XLSX plugin.
by Chris Vecchio
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Export XLSX Demo</title>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://cdn.jsdelivr.net/npm/exceljs@latest/dist/exceljs.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/file-saver@latest/dist/FileSaver.min.js"></script>
<script src="https://cdn.statically.io/gh/SheetJS/ssf/e267d1d6/ssf.js"></script>
<script src="https://cdn.statically.io/gh/chris-vecchio/export-xlsx/4750dc12/js/exportxlsx.js"></script>
</head>
<body>
<div class="chart" id="chart-container-1"></div>
<div class="chart" id="chart-container-2"></div>
<div class="chart" id="chart-container-3"></div>
<div class="chart" id="chart-container-4"></div>
<div class="chart" id="chart-container-5"></div>
</body>
</html>
CSS
.chart {
display: block;
border: solid 1px #dbd9d9;
width: 560px;
height: 420px;
}
JavaScript
$(document).ready(function() {
var chartOptions1 = {
chart: {
zoomType: 'x'
},
exporting: {
filename: 'export_xlsx_example',
csv: {
// Test export-xlsx interface with columnHeaderFormatter function
// The column headers in the exported workbook should be as follows:
// FormatterName, Less than HS, HS, Some College Mod, Bachelor Degree & Higher Mod
columnHeaderFormatter: function(item, key) {
if (!item || item instanceof Highcharts.Axis) {
return item.options.title.text || 'FormatterName';
}
// Item is not axis, now we are working with series.
// Key is the property on the series we show in this column.
else {
return item.name + ' Mod';
}
}
},
xlsx: {
worksheet: {
autoFitColumns: true,
categoryColumn: {
numberFormat: 'yyyy-mm'
}
},
workbook: {
fileProperties: {
creator: "File Author",
company: "File Company",
created: new Date(2017, 11, 31)
}
}
}
},
title: {
text: 'US Unemployment Rates by Educational Attainment',
},
yAxis: {
title: {
text: 'Percent'
}
},
xAxis: {
type: 'datetime',
title: {
text: null
}
},
plotOptions: {
series: {
pointStart: Date.UTC(2007, 0, 1),
pointIntervalUnit: 'month',
marker: {
enabled: false
...