当前位置: 首页 > news >正文

react native中使用echarts

开发平台:mac pro

node版本:v8.11.2

npm版本:6.4.1

react-native版本:0.57.8

native-echarts版本:^0.5.0
目标平台:android端收银机,android7.0+

 

最近在使用react native进行app的开发工作,rn开发的内容会与原生app混合,在一些使用场景下遇到了一些问题

 

使用场景:每日收益与每月收益的折线图统计

 

在pc/h5端的开发工作中,图标类的开发使用echarts/f2等三方工具都是比较常见的了,在react native中,没有了DOM的概念,因此在react native中使用了一些三方的图标库

native-echarts,github地址。

 

需要更换echarts版本的方法

native-echarts内部使用了react native中的webview进行图表的展示,本质上只是传入数据,通过echarts渲染出静态的HTML文档,然后通过webview展示出来而已。

netive-echarts内部使用的echarts版本为v3.2.3"版本,如果需要更高级的echarts版本,只需要更换src/components/Echarts/echarts.min.js文件以及tpl.html文件里的内容即可。

 

使用时遇到的问题: 在debug模式下,真机以及测试机器上图标正常显示,打包成android的apk文件后图表都不显示

解决方式:

1:找到native-echarts/src/components/Echarts/tpl.html文件,复制到android/app/src/main/assets这个目录下面,如果文件夹不存在就新建一个即可。

2:找到文件native-echarts/src/components/Echarts/index.js,修改为一下内容

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 {

    constructor(props) {
      super(props);
    }
    

    // 预防过渡渲染
    shouldComponentUpdate(nextProps, nextState) {
      const thisProps = this.props || {}
      nextProps = nextProps || {}
      if (Object.keys(thisProps).length !== Object.keys(nextProps).length) {
        return true
      }
      for (const key in nextProps) {
        if (JSON.stringify(thisProps[key]) != JSON.stringify(nextProps[key])) {
          // console.log('props', key, thisProps[key], nextProps[key])
          return true
        }
      }
      return false
    }

    componentWillReceiveProps(nextProps) {
      if (nextProps.option !== this.props.option) {
        // 解决数据改变时页面闪烁的问题
        this.refs.chart.injectJavaScript(renderChart(nextProps))
      }
    }

    render() {
      return (
        <View style={{flex: 1, height: this.props.height || 400,}}>
          <WebView
            ref="chart"
            scrollEnabled = {false}
            injectedJavaScript = {renderChart(this.props)}
            style={{
              height: this.props.height || 400,
              backgroundColor: this.props.backgroundColor || 'transparent'
            }}
            scalesPageToFit={Platform.OS !== 'ios'}
            originWhitelist={['*']}
            source={{uri: 'file:///android_asset/tpl.html'}}
            onMessage={event => this.props.onPress ? this.props.onPress(JSON.parse(event.nativeEvent.data)) : null}
          />
        </View>
      );
    }
  }

 

可能存在的问题????

 

同时,在后续的react native版本中,webview即将从react native内部移除出去,改为三方包安装使用。参考:

https://reactnative.cn/docs/webview/#mixedcontentmode

https://github.com/react-native-community/discussions-and-proposals/issues/6

因此,在后续新版本中使用native-echarts,可能会使用不了,因此建议fork一个稳定的版本到自己的github上,或者在后续自己采用react-native-webview + echarts的方式自由的组合版本,使用起来更加自由。

 

 

参考文档:

https://github.com/somonus/react-native-echarts/issues/47

https://github.com/somonus/react-native-echarts/issues/32

https://github.com/somonus/react-native-echarts/issues/122

 

 

转载于:https://www.cnblogs.com/sk-3/p/10533490.html

相关文章:

  • JQuery中$.ajax()方法参数详解
  • 理解 JavaScript Mutation 突变和 PureFunction 纯函数
  • table tr,td,div ... focus
  • 数控切割机造船行业应用
  • 小明的调查作业
  • virtualbox 不能为虚拟电脑打开一个新任务/VT-x features locked or unavailable in MSR.
  • Linux Cluster
  • Mac开发环境配置相关:/usr/include缺失了怎么办?
  • [2019.2.28]BZOJ4033 [HAOI2015]树上染色
  • 正确优雅地解决用户退出——JSP及Struts解决方案
  • 亚马逊是如何进行软件开发的
  • zookeeper系列之一—zookeeper入门
  • vuex视频教程
  • 关于 +new Date 的个人见解
  • JOB SERVER 负载均衡
  • 网络传输文件的问题
  • [deviceone开发]-do_Webview的基本示例
  • httpie使用详解
  • Javascripit类型转换比较那点事儿,双等号(==)
  • jquery cookie
  • JS正则表达式精简教程(JavaScript RegExp 对象)
  • rabbitmq延迟消息示例
  • spring cloud gateway 源码解析(4)跨域问题处理
  • spring学习第二天
  • 闭包--闭包之tab栏切换(四)
  • 创建一种深思熟虑的文化
  • 服务器之间,相同帐号,实现免密钥登录
  • 实现菜单下拉伸展折叠效果demo
  • 它承受着该等级不该有的简单, leetcode 564 寻找最近的回文数
  • 小程序 setData 学问多
  • 携程小程序初体验
  • 用Node EJS写一个爬虫脚本每天定时给心爱的她发一封暖心邮件
  • 怎么将电脑中的声音录制成WAV格式
  • Spring Batch JSON 支持
  • zabbix3.2监控linux磁盘IO
  • 国内唯一,阿里云入选全球区块链云服务报告,领先AWS、Google ...
  • (10)工业界推荐系统-小红书推荐场景及内部实践【排序模型的特征】
  • (第27天)Oracle 数据泵转换分区表
  • (免费分享)基于springboot,vue疗养中心管理系统
  • (十)DDRC架构组成、效率Efficiency及功能实现
  • (原)记一次CentOS7 磁盘空间大小异常的解决过程
  • (转)自己动手搭建Nginx+memcache+xdebug+php运行环境绿色版 For windows版
  • (轉貼) VS2005 快捷键 (初級) (.NET) (Visual Studio)
  • .Net Redis的秒杀Dome和异步执行
  • .Net(C#)常用转换byte转uint32、byte转float等
  • .net反混淆脱壳工具de4dot的使用
  • .NET文档生成工具ADB使用图文教程
  • .pop ----remove 删除
  • .sh
  • .ui文件相关
  • @Transaction注解失效的几种场景(附有示例代码)
  • [20161101]rman备份与数据文件变化7.txt
  • [20190416]完善shared latch测试脚本2.txt
  • [AutoSAR 存储] 汽车智能座舱的存储需求
  • [BUUCTF NewStarCTF 2023 公开赛道] week4 crypto/pwn