react-native-echarts/example/index.android.js

103 lines
2.1 KiB
JavaScript
Raw Normal View History

2016-10-21 07:05:57 +00:00
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
2016-11-03 02:55:11 +00:00
View,
TouchableOpacity
2016-10-21 07:05:57 +00:00
} from 'react-native';
2016-10-21 07:54:29 +00:00
import Echarts from 'native-echarts';
2016-10-21 07:05:57 +00:00
export default class app2 extends Component {
2016-11-03 02:55:11 +00:00
constructor(props) {
super(props);
this.state = {
option : {
title: {
text: 'ECharts 入门示例'
},
tooltip: {},
legend: {
data:['销量']
},
xAxis: {
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
2016-10-21 07:54:29 +00:00
},
2016-11-03 02:55:11 +00:00
text: 'test'
2016-10-21 07:54:29 +00:00
};
2016-11-03 02:55:11 +00:00
}
changeOption() {
this.setState({
option: {
title: {
text: 'New Chart'
},
tooltip: {},
legend: {
data:['销量']
},
xAxis: {
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
},
yAxis: {},
series: [{
name: '销量',
type: 'line',
data: [5, 20, 36, 10, 10, 20]
}]
}
})
}
render() {
2016-10-21 07:05:57 +00:00
return (
<View style={styles.container}>
<Text style={styles.welcome}>
2016-10-21 07:54:29 +00:00
Welcome to React Native Echarts!
2016-10-21 07:05:57 +00:00
</Text>
2016-11-03 02:55:11 +00:00
<TouchableOpacity style={styles.button} onPress={this.changeOption.bind(this)}>
<Text style={{color: '#fff'}}>change state</Text>
</TouchableOpacity>
<Echarts option={this.state.option} height={300} />
2016-10-21 07:05:57 +00:00
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
2016-10-21 07:54:29 +00:00
margin: 30,
2016-10-21 07:05:57 +00:00
},
2016-11-03 02:55:11 +00:00
button: {
backgroundColor: '#d9534f',
padding: 8,
borderRadius: 4,
marginBottom: 20
}
2016-10-21 07:05:57 +00:00
});
AppRegistry.registerComponent('app2', () => app2);