添加一个主动刷新option的方法,界面不会闪动
This commit is contained in:
parent
9ee6a04c9d
commit
78133f76f5
|
|
@ -4,12 +4,23 @@ import renderChart from './renderChart';
|
||||||
import echarts from './echarts.min';
|
import echarts from './echarts.min';
|
||||||
|
|
||||||
export default class App extends Component {
|
export default class App extends Component {
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.setNewOption = this.setNewOption.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
if(nextProps.option !== this.props.option) {
|
if(nextProps.option !== this.props.option) {
|
||||||
this.refs.chart.reload();
|
this.refs.chart.reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setNewOption(option) {
|
||||||
|
this.refs.chart.postMessage(JSON.stringify(option));
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<View style={{flex: 1, height: this.props.height || 400,}}>
|
<View style={{flex: 1, height: this.props.height || 400,}}>
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,10 @@ export default function renderChart(props) {
|
||||||
document.getElementById('main').style.width = "${width}";
|
document.getElementById('main').style.width = "${width}";
|
||||||
var myChart = echarts.init(document.getElementById('main'));
|
var myChart = echarts.init(document.getElementById('main'));
|
||||||
myChart.setOption(${toString(props.option)});
|
myChart.setOption(${toString(props.option)});
|
||||||
|
window.document.addEventListener('message', function(e) {
|
||||||
|
var option = JSON.parse(e.data);
|
||||||
|
myChart.setOption(option);
|
||||||
|
});
|
||||||
myChart.on('click', function(params) {
|
myChart.on('click', function(params) {
|
||||||
var seen = [];
|
var seen = [];
|
||||||
var paramsString = JSON.stringify(params, function(key, val) {
|
var paramsString = JSON.stringify(params, function(key, val) {
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,15 @@ import { WebView, View } from 'react-native';
|
||||||
import { Container, Echarts } from './components'
|
import { Container, Echarts } from './components'
|
||||||
|
|
||||||
export default class App extends Component {
|
export default class App extends Component {
|
||||||
|
|
||||||
|
setNewOption(option) {
|
||||||
|
this.chart.setNewOption(option);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<Container width={this.props.width}>
|
<Container width={this.props.width}>
|
||||||
<Echarts {...this.props} />
|
<Echarts {...this.props} ref={e => this.chart = e}/>
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue