UNPKG

@p2m/react-native-echarts

Version:
31 lines (27 loc) 1.1 kB
import {toString} from './utils'; const renderChart = (props) => { const height = `${props.height || 400}px`; const width = props.width ? `${props.width}px` : 'auto'; const backgroundColor = props.backgroundColor; return ` document.getElementById('main').style.height = "${height}"; document.getElementById('main').style.width = "${width}"; document.getElementById('main').style.backgroundColor = "${backgroundColor}"; var myChart = echarts.init(document.getElementById('main')); myChart.setOption(${toString(props.option)}); 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; }); window.ReactNativeWebView.postMessage(JSON.stringify({"types":"ON_PRESS","payload": paramsString})); }); ` } export default renderChart;