2016-10-21 07:54:29 +00:00
|
|
|
import echarts from './echarts.min';
|
2016-10-27 06:14:35 +00:00
|
|
|
import toString from '../../util/toString';
|
2016-10-21 07:54:29 +00:00
|
|
|
|
2016-11-01 09:31:14 +00:00
|
|
|
export default function renderChart(props) {
|
2017-05-15 06:48:47 +00:00
|
|
|
const height = `${props.height || 400}px`;
|
|
|
|
|
const width = props.width ? `${props.width}px` : 'auto';
|
2016-10-21 07:54:29 +00:00
|
|
|
return `
|
2017-05-15 06:48:47 +00:00
|
|
|
document.getElementById('main').style.height = "${height}";
|
|
|
|
|
document.getElementById('main').style.width = "${width}";
|
2016-11-01 09:31:14 +00:00
|
|
|
var myChart = echarts.init(document.getElementById('main'));
|
|
|
|
|
myChart.setOption(${toString(props.option)});
|
2018-01-03 00:27:48 +00:00
|
|
|
window.document.addEventListener('message', function(e) {
|
|
|
|
|
var option = JSON.parse(e.data);
|
|
|
|
|
myChart.setOption(option);
|
|
|
|
|
});
|
2017-05-13 01:13:47 +00:00
|
|
|
myChart.on('click', function(params) {
|
|
|
|
|
var seen = [];
|
|
|
|
|
var paramsString = JSON.stringify(params, function(key, val) {
|
|
|
|
|
if (val != null && typeof val == "object") {
|
|
|
|
|
if (seen.indexOf(val) >= 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
seen.push(val);
|
|
|
|
|
}
|
|
|
|
|
return val;
|
|
|
|
|
});
|
2017-05-13 01:24:48 +00:00
|
|
|
window.postMessage(paramsString);
|
2017-05-13 01:13:47 +00:00
|
|
|
});
|
2016-11-01 09:31:14 +00:00
|
|
|
`
|
2016-10-21 07:54:29 +00:00
|
|
|
}
|