fix the bug when option contains function
This commit is contained in:
parent
d7577f445d
commit
b3152edbf2
|
|
@ -1,4 +1,5 @@
|
|||
import echarts from './echarts.min';
|
||||
import toString from '../../util/toString';
|
||||
|
||||
export default function renderChart(option) {
|
||||
return `
|
||||
|
|
@ -30,7 +31,7 @@ export default function renderChart(option) {
|
|||
// 基于准备好的dom,初始化echarts实例
|
||||
var myChart = echarts.init(document.getElementById('main'));
|
||||
// 使用刚指定的配置项和数据显示图表。
|
||||
myChart.setOption(${JSON.stringify(option)});
|
||||
myChart.setOption(${toString(option)});
|
||||
</script>
|
||||
<body>
|
||||
<html>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
export default function toString(obj) {
|
||||
return JSON.stringify(obj, function(key, val) {
|
||||
if (typeof val === 'function') {
|
||||
return `~--demo--~${val}~--demo--~`;
|
||||
}
|
||||
return val;
|
||||
}).replace('\"~--demo--~', '').replace('~--demo--~\"', '').replace(/\\n/g, '');
|
||||
}
|
||||
Loading…
Reference in New Issue