react-native-echarts/src/components/Echarts/renderChart.js

27 lines
861 B
JavaScript
Raw Normal View History

2016-10-21 07:54:29 +00:00
import echarts from './echarts.min';
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)});
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
}