diff --git a/src/components/Echarts/renderChart.js b/src/components/Echarts/renderChart.js index 04f4cd9..e76b23a 100644 --- a/src/components/Echarts/renderChart.js +++ b/src/components/Echarts/renderChart.js @@ -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)}); diff --git a/src/util/toString.js b/src/util/toString.js new file mode 100644 index 0000000..ac379ba --- /dev/null +++ b/src/util/toString.js @@ -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, ''); +}