react-native-echarts是react native結合百度echart的圖表,集成的一個圖表插件。javascript
github地址:https://github.com/zhangxinagjunHJH/react-native-echartshtml
echart地址:http://echarts.baidu.com/examples/index.html 能夠看到官方API很強大,圖表種類很是多java
按照官網所寫,app在模擬器上運行正常,可是打包時出現圖表不顯示問題,下面先介紹按照和使用方法,再介紹解決問題方案。node
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);
安裝後,可在模擬器上運行,顯示沒問題,可是在真機上一試,顯示不出圖表。react
把「\node_modules\native-echarts\src\components\Echarts\tpl.html」文件複製一份放在「android/app/src/main/assets」文件裏,若是「android/app/src/main」下沒有「assets」文件,就建一個。修改後,在android
android模擬器上運行就正常顯示圖表了。git