react native 使用echarts 是在HTML展示图表,通过webview引入html

安装webview

yarn add react-native-webview

通过下面命令安装

yarn add native-echarts

安装完成之后在node_modules 生成文件夹native-echarts。

这样安装的组件还有问题,

(1)组件中引用的webview是react-native自带的,但是最近几个版本已经没有了,需要引入上面安装的webview

import React, { Component } from 'react';
import { WebView, View } from 'react-native';
import { Container, Echarts } from './components'

将这个组件中所有引入webview的替换为

import WebView from "react-native-webview";

(2)webview引入html

找到

   <WebViewref="chart"scrollEnabled = {false}injectedJavaScript = {renderChart(this.props)}style={{height: this.props.height || 400,backgroundColor: this.props.backgroundColor || 'transparent'}}scalesPageToFit={Platform.OS !== 'ios'}originWhitelist={['*']}source={require('./tpl.html')}onMessage={event => this.props.onPress ? this.props.onPress(JSON.parse(event.nativeEvent.data)) : null}/>

改成

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

将tpl.html复制一份放在 项目\android\app\src\main

webview 的source是引入html,在Android端 require此方式不会进行html解析.

基础使用
native-echarts的使用方法基本和网页端的Echarts使用方法一致。组件主要有三个属性:

option (object):图表的相关配置和数据。详见文档:ECharts Documentation
width (number):图表的宽度,默认值是外部容器的宽度。
height (number) :图表的高度,默认值是400。

import React, { Component } from 'react';
import {AppRegistry,StyleSheet,Text,View
} from 'react-native';
import Echarts from 'native-echarts';export default class Index extends Component {render() {const option = {tooltip: {trigger: 'axis',axisPointer: {type: 'cross',crossStyle: {color: '#999'}}},toolbox: {feature: {dataView: { show: true, readOnly: false },magicType: { show: true, type: ['line', 'bar'] },restore: { show: true },saveAsImage: { show: true }}},legend: {data: ['Evaporation', 'Temperature']},xAxis: [{type: 'category',data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],axisPointer: {type: 'shadow'}}],yAxis: [{type: 'value',name: 'Precipitation',min: 0,max: 250,interval: 50,axisLabel: {formatter: '{value} ml'}},{type: 'value',name: 'Temperature',min: 0,max: 25,interval: 5,axisLabel: {formatter: '{value} °C'}}],series: [{name: 'Evaporation',type: 'bar',data: [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]},{name: 'Temperature',type: 'line',yAxisIndex: 1,data: [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]}]
};return (<Echarts option={option} height={300} />);}
}

react native使用echarts图表相关推荐

  1. 如何使用动态工具提示构建React Native图表

    by Vikrant Negi 通过Vikrant Negi 如何使用动态工具提示构建React Native图表 (How to build React Native charts with dyn ...

  2. react可视化项目 ECharts 3D区域地图图表+点击取消高亮黄色

    react 可视化项目 ECharts 3D区域地图图表 地图介绍 echarts图表引入 react页面中引入使用 地图介绍 做可视化项目时需要3d的区域地图,在网上搜到ECharts社区的一个其他 ...

  3. React中使用echarts绘制图表

    我们都知道,Echarts图表功能非常强大,使用起来也很方便,我们的项目中就用到了Echarts,现在笔者就带大家看看怎么在react中使用Echarts. 我们要想在react项目中高效使用echa ...

  4. React Native图表插件

    React Native图表插件react-native-charts-wrapper集成教程 https://www.jianshu.com/p/432517c5b531

  5. 【React自制全家桶】一、Webstrom+React+Ant Design+echarts搭建react项目

    前言 一.React是Facebook推出的一个前端框架,之前被用于著名的社交媒体Instagram中,后来由于取得了不错的反响,于是Facebook决定将其开源.出身名门的React也不负众望,成功 ...

  6. echarts setoption方法_在Vue和React中使用ECharts的多种方法

    前言 俗话说:"工欲善其事,必先利其器".现如今已经有许多成熟易用的可视化解决方案,例如ECharts,AntV等等.我们可以把这些解决方案比作是一套套成熟的"工具&qu ...

  7. Shoutem旨在成为React Native移动应用领域的WordPress

    近日,Shoutem推出了新的基于React Native的应用构建器,为开发人员提供了移动应用领域的WordPress. \\ Shoutem让开发人员可以使用一个可视化环境快速创建基于React ...

  8. 如何在React Native中创建精美的动画加载器

    by Vikrant Negi 通过Vikrant Negi 如何在React Native中创建精美的动画加载器 (How to create a beautifully animated load ...

  9. 如何构建具有实时搜索功能的React Native FlatList

    by Vikrant Negi 通过Vikrant Negi 如何构建具有实时搜索功能的React Native FlatList (How to build a React Native FlatL ...

  10. React Native常用第三方汇总

    React Native 项目常用第三方组件汇总:  react-native-animatable 动画  react-navigation  github : https://reactnavig ...

最新文章

  1. python中表示换行的符号_对Python字符串中的换行符和制表符介绍
  2. Shell终端快捷键总结(mac)
  3. linux沙箱隔离_Linux沙箱技术介绍
  4. 权值线段树小结(hdu多校,普通平衡树,郁闷的出纳员)
  5. LwIP应用开发笔记之三:LwIP无操作系统UDP客户端
  6. leetcode206题:反转链表(迭代或是递归)
  7. 2020年中国最具影响力的50位商界领袖:马云、任正非、王传福位列前三
  8. 会玩!抖音上线拉春联特效 “拜个抖音年”活动参与人数超65万
  9. Android ListView 技巧 (一) Android ListView Header
  10. CFA要学哪些课程?零基础怎么学CFA呢?
  11. outlook2010保留服务器邮件,outlook 保留服务器邮件
  12. Comparator.comparing()比较排序(可以jdk8 Strim()结合) 可以通过这个比较排序
  13. 哈哈...汗汗...
  14. 欢迎注册和登陆我们的学海灯塔
  15. pycharm软件中去掉竖线的方法
  16. 第23次CSP认证(202109)
  17. ubuntu安装mysql忘记密码并重置
  18. 一分钟知道屏幕分辨率、尺寸、PPI之间的关系!!!
  19. 弹性均质圆环法计算过程_同济大学地下建筑结构复习要点
  20. mysql最高安全级别双一_MySQL技术体系之核心参数

热门文章

  1. ZIP RAR文件密码破解软件ARCHPR Pro4.54(绿色中文破解版)
  2. C语言课程设计——电影院订票系统
  3. 特征根法求微分方程的解
  4. 量子计算实现:量子算法的实现
  5. Windows蓝屏的解决办法(如:UNEXPECTED_STORE_EXCEPTION蓝屏)
  6. blos硬盘启动台式计算机,bios设置硬盘启动,最全的bios设置硬盘启动详细方法(两种模式)...
  7. 如何下载B站视频(方法持续更新)
  8. 平均销售额计算机公式,销售额是什么意思(销售额的基本计算公式)
  9. 西南民族大学计算机院方导师,暨南大学信息科学技术学院导师教师师资介绍简介-高博宇...
  10. safari浏览器关于时间日期格式的兼容问题