Skip to content

Use js-xlsx library to allow to download Excel files from the displayed data #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
"name": "widget",
"dependencies": {
"moment": "2.22.2",
"echarts": "4.2.0-rc.2"
"echarts": "4.2.0-rc.2",
"js-xlsx": "0.15.2"
},
"exportsOverride": {
"echarts": {
"js": "dist/echarts.min.js"
},
"moment": {
"js": "min/moment-with-locales.min.js"
},
"js-xlsx": {
"js": "dist/xlsx.mini.min.js"
}
}
}
4 changes: 2 additions & 2 deletions src/config.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version='1.0' encoding='UTF-8'?>
<widget xmlns="http://wirecloud.conwet.fi.upm.es/ns/macdescription/1" vendor="Ficodes" name="echarts" version="0.0.2">
<widget xmlns="http://wirecloud.conwet.fi.upm.es/ns/macdescription/1" vendor="Ficodes" name="echarts" version="0.0.3a3">

<details>
<title>ECharts widget</title>
<title>ECharts</title>
<homepage>https://github.com/Wirecloud/echarts-widget</homepage>
<authors>Carlos Blanco &lt;[email protected]&gt;</authors>
<email>[email protected]</email>
Expand Down
6 changes: 4 additions & 2 deletions src/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ html {
width: 100%;
height:100%;
}

body {
font-family: 'Open Sans', sans-serif;
font-size: 12px;
color: #4A4A4A;
background-color: #f9f9f9;
width: 100%;
height:100%;
}
height: 100%;
margin: 0px;
}
3 changes: 1 addition & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
<script src="lib/js/moment-with-locales.min.js"></script>

<!-- including eCharts lib -->
<!--<script src="lib/echarts_4.2.0-rc.2/echarts.min.js"></script>-->

<script src="lib/js/xlsx.mini.min.js"></script>
<script src="lib/js/echarts.min.js"></script>

<!-- style -->
Expand Down
23 changes: 21 additions & 2 deletions src/js/ECharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

/* exported ECharts */
/* globals echarts */
/* globals echarts, XLSX */


var ECharts = (function () {
Expand Down Expand Up @@ -73,7 +73,26 @@ var ECharts = (function () {
echart.clear();
echart.showLoading();

if (data && typeof data === "object") {
if (typeof data === "object") {
if (data.toolbox != null && data.toolbox.feature != null && data.toolbox.feature.saveAsExcel != null) {
data.toolbox.feature.mySaveAsExcel = data.toolbox.feature.saveAsExcel;
data.toolbox.feature.mySaveAsExcel.title = "Excel";
data.toolbox.feature.mySaveAsExcel.icon = "path://M432.45,595.444c0,2.177-4.661,6.82-11.305,6.82c-6.475,0-11.306-4.567-11.306-6.82s4.852-6.812,11.306-6.812C427.841,588.632,432.452,593.191,432.45,595.444L432.45,595.444z M421.155,589.876c-3.009,0-5.448,2.495-5.448,5.572s2.439,5.572,5.448,5.572c3.01,0,5.449-2.495,5.449-5.572C426.604,592.371,424.165,589.876,421.155,589.876L421.155,589.876z M421.146,591.891c-1.916,0-3.47,1.589-3.47,3.549c0,1.959,1.554,3.548,3.47,3.548s3.469-1.589,3.469-3.548C424.614,593.479,423.062,591.891,421.146,591.891L421.146,591.891zM421.146,591.891";
data.toolbox.feature.mySaveAsExcel.onclick = () => {
let wb = XLSX.utils.book_new();
let aoa = data.xAxis[0].data.map((x, index) => {
let row = [x + 'Z'];
data.series.forEach((serie) => {
row.push(serie.data[index] * 100);
});
return row;
});
aoa.splice(0, 0, ["dateObserved", "fillLevel"]);
XLSX.utils.book_append_sheet(wb, XLSX.utils.aoa_to_sheet(aoa), 'data')
XLSX.writeFile(wb, 'data.xlsx');
};
delete data.toolbox.feature.saveAsExcel;
}
try {
echart.setOption(data, true);
} catch (e) {
Expand Down
22 changes: 0 additions & 22 deletions src/lib/echarts_4.2.0-rc.2/echarts.min.js

This file was deleted.