mirror of
https://github.com/dillonzq/LoveIt.git
synced 2024-11-14 19:06:16 +01:00
load echarts as JS modules if data-filename attr
This commit is contained in:
parent
b81607c09e
commit
137e99df11
1 changed files with 14 additions and 2 deletions
|
@ -515,8 +515,20 @@ class Theme {
|
|||
}
|
||||
this._echartsArr = [];
|
||||
this.util.forEach(document.getElementsByClassName('echarts'), $echarts => {
|
||||
const chart = echarts.init($echarts, this.isDark ? 'dark' : 'light', {renderer: 'svg'});
|
||||
chart.setOption(JSON.parse(this.data[$echarts.id]));
|
||||
let filename = $echarts.dataset.filename;
|
||||
const chart = echarts.init($echarts, this.isDark ? 'dark' : 'macarons', {renderer: 'svg'});
|
||||
if (! filename) {
|
||||
// has chart config stored in some element ID as JSON
|
||||
chart.setOption(JSON.parse(this.data[$echarts.id]));
|
||||
} else {
|
||||
// has data-filename attribute => load chart config from external file
|
||||
$echarts.innerHTML = '';
|
||||
import(filename).then(module => {
|
||||
chart.setOption(module.option);
|
||||
}).catch((err) => {
|
||||
console.error("While loading eChart for " + filename + ": " + err);
|
||||
})
|
||||
}
|
||||
this._echartsArr.push(chart);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue