npm install native-echarts --save
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
import Echarts from 'native-echarts';
export default class app extends Component {
render() {
const option = {
title: {
text: 'ECharts demo'
},
tooltip: {},
legend: {
data:['销量']
},
xAxis: {
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
};
return (
<Echarts option={option} height={300} />
);
}
}
AppRegistry.registerComponent('app', () => app);
import echarts from './echarts.min';
import toString from '../../util/toString';
export default function renderChart(props) {
const height = props.height || 400;
const width = props.width || 568;
return `
document.getElementById('main').style.height = "${height}px";
document.getElementById('main').style.width = "${width}px";
var myChart = echarts.init(document.getElementById('main'));
myChart.setOption(${toString(props.option)});
myChart.on('click', function (params) {
var message = {};
message.event='click';
message.seriesName = params.seriesName;
message.name = params.name;
window.postMessage(JSON.stringify(message));
});
`
}
import React, { Component } from 'react';
import { WebView, View, StyleSheet, Platform } from 'react-native';
import renderChart from './renderChart';
import echarts from './echarts.min';
export default class App extends Component {
componentWillReceiveProps(nextProps) {
if(JSON.stringify(nextProps.option) !== JSON.stringify(this.props.option)) {
this.refs.chart.reload();
}
}
handleMessage = (evt) => {
const message = JSON.parse(evt.nativeEvent.data)
this.props.handleMessage(message);
}
render() {
return (
<View style={{flex: 1, height: this.props.height,width: this.props.width }}>
<WebView
ref="chart"
scrollEnabled = {false}
injectedJavaScript = {renderChart(this.props)}
style={{
height: this.props.height|| 400,
width: this.props.width || 568,
}}
onMessage={this.handleMessage}
source={require('./tpl.html')}
/>
</View>
);
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有