react-native-echarts

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

相关文章
相关标签/搜索
本站公众号
   欢迎关注本站公众号,获取更多信息