BIChartsItem.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. import React, { Component } from 'react';
  2. import {
  3. StyleSheet,
  4. Text,
  5. View,
  6. TouchableOpacity,
  7. Image,
  8. } from 'react-native';
  9. import {NativeModules} from 'react-native';
  10. const YRRnBridge = NativeModules.YRRnBridge;
  11. import Echarts from 'native-echarts';
  12. import Dimensions from 'Dimensions';
  13. import NavigationUtil from "../../navigator/NavigationUtil";
  14. const {width} = Dimensions.get('window');
  15. export default class BIChartsItem extends Component {
  16. constructor(props) {
  17. super(props);
  18. const{typeTitle} = this.props;
  19. const typeOptions = {
  20. apple:[2, 4, 7, 2, 2, 7, 13, 16],
  21. organ: [6, 9, 9, 2, 8, 7, 17, 18],
  22. banana: [6, 9, 3, 2, 8, 7, 1, 8],
  23. }
  24. const option = {
  25. title:{
  26. text:'水果对比',
  27. top:'0',
  28. left:'10',
  29. font:10,
  30. textStyle:{
  31. fontSize: 18,
  32. color:'darkGray',
  33. }
  34. },
  35. //点击某一个点的数据的时候,显示出悬浮窗
  36. tooltip : {
  37. trigger: 'axis'
  38. },
  39. //可以手动选择现实几个图标
  40. legend: {
  41. padding:[
  42. 240,
  43. 100,
  44. 100,
  45. 100,
  46. ],
  47. data:['苹果','橘子','香蕉']
  48. },
  49. //各种表格
  50. toolbox: {
  51. //改变icon的布局朝向
  52. orient: 'horizontal',
  53. show : false,
  54. showTitle:true,
  55. feature : {
  56. //show是否显示表格,readOnly是否只读
  57. dataView : {show: true, readOnly: true},
  58. magicType : {
  59. //折线图 柱形图 总数统计 分开平铺
  60. type: ['line', 'bar','stack','tiled'],
  61. },
  62. }
  63. },
  64. xAxis : [
  65. {
  66. //就是一月份这个显示为一个线段,而不是数轴那种一个点点
  67. boundaryGap:true,
  68. type : 'category',
  69. name : '时间',
  70. data : ['1月','2月','3月','4月','5月','6月','7月','8月']
  71. }
  72. ],
  73. yAxis : [
  74. {
  75. type : 'value',
  76. name : '销量(kg)'
  77. }
  78. ],
  79. //图形的颜色组
  80. color:['rgb(249,159,94)','rgb(67,205,126)','rgb(167,205,126)'],
  81. //需要显示的图形名称,类型,以及数据设置
  82. series : [
  83. {
  84. name:'苹果',
  85. //默认显
  86. type:typeTitle,
  87. data:typeOptions.apple
  88. },
  89. {
  90. name:'橘子',
  91. type:typeTitle,
  92. data:typeOptions.organ
  93. },{
  94. name:'香蕉',
  95. type:typeTitle,
  96. data:typeOptions.banana
  97. }
  98. ]
  99. };
  100. const pieOptions = {
  101. title:{
  102. text:'水果对比',
  103. top:'0',
  104. left:'10',
  105. font:10,
  106. textStyle:{
  107. fontSize: 18,
  108. color:'darkGray',
  109. }
  110. },
  111. legend: {
  112. orient: 'horizontal',
  113. type:'scroll',
  114. data: ['直接访问','邮件营销','联盟广告','视频广告','搜索引擎'],
  115. padding:[
  116. 240,
  117. 100,
  118. 100,
  119. 100,
  120. ],
  121. },
  122. series : [
  123. {
  124. name: '访问来源',
  125. type: 'pie',
  126. radius : '55%',
  127. center: ['50%', '50%'],
  128. data:[
  129. {value:335, name:'直接访问'},
  130. {value:310, name:'邮件营销'},
  131. {value:334, name:'联盟广告'},
  132. {value:135, name:'视频广告'},
  133. {value:548, name:'搜索引擎'}
  134. ],
  135. itemStyle: {
  136. emphasis: {
  137. shadowBlur: 10,
  138. shadowOffsetX: 0,
  139. shadowColor: 'rgba(0, 0, 0, 0.5)'
  140. }
  141. }
  142. }
  143. ]
  144. };
  145. this.state = {
  146. options: typeTitle === 'pie' ? pieOptions:option,
  147. }
  148. }
  149. _onPressAllScreen(){
  150. NavigationUtil.goPage(this.state.options,'AllScreenChart',)
  151. }
  152. render() {
  153. return (
  154. <View style={styles.cell_content}>
  155. <View style={styles.topView}>
  156. <Text style={styles.topView_title}>
  157. 今年水果排行榜和种类
  158. </Text>
  159. <TouchableOpacity
  160. style = {styles.topView_touch}
  161. onPress={()=>this._onPressAllScreen()}
  162. >
  163. <Image style={styles.topView_image}
  164. source={{uri: 'bi_allScreen'}}
  165. >
  166. </Image>
  167. </TouchableOpacity>
  168. </View>
  169. <Echarts option={this.state.options} height={260} width={width}/>
  170. </View>
  171. );
  172. }
  173. }
  174. const styles = StyleSheet.create({
  175. cell_content:{
  176. backgroundColor:'white',
  177. padding:10,
  178. marginTop:10,
  179. marginLeft:10,
  180. marginRight:10,
  181. marginVertical:3,
  182. borderColor:'#dddddd',
  183. borderWidth:0.5,
  184. borderRadius:8,
  185. shadowColor:'gray',
  186. shadowOffset:{width: 2,height: 2},
  187. shadowOpacity:0.4,
  188. shadowRadius:1,
  189. elevation: 2,
  190. },
  191. topView:{
  192. height: 30,
  193. justifyContent:'space-between',
  194. flexDirection:'row',
  195. },
  196. topView_title:{
  197. fontSize:18,
  198. color: '#333333',
  199. height:30,
  200. marginLeft: 10,
  201. width:200,
  202. lineHeight:30,
  203. },
  204. topView_touch:{
  205. padding:1,
  206. height:30,
  207. width:30,
  208. },
  209. topView_image:{
  210. marginTop:5,
  211. height:20,
  212. width:20,
  213. },
  214. });