react-native echarts(Android)

附地址:https://github.com/somonus/react-native-echarts

1、安装

npm install native-echarts --save

2、使用

import Echarts from 'native-echarts';

const option = {
            backgroundColor: '#fff',
            title: {
                text: '生长记录统计',
                x: 'center',
                top: 6
            },
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            color: ['#f5222d', '#1890ff', '#52c41a', '#F6BE0F'],
            legend: {
                orient: 'vertical',
                left: 6,
                top: 6,
                data: ['尚未记录', '记录中', '待收获', '已收获']
            },
            series: [
                {
                    name: '生长记录统计',
                    type: 'pie',
                    radius: '55%',
                    center: ['50%', '60%'],
                    label: {
                        normal: {
                            formatter: "{b} : {c}批"
                        }
                    },
                    data: [
                        {value: 15, name: '尚未记录'},
                        {value: 53, name: '记录中'},
                        {value: 20, name: '待收获'},
                        {value: 124, name: '已收获'}
                    ],
                    itemStyle: {
                        emphasis: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        };

<Echarts option={option} height={300} width={width - 20} scalesPageToFit={true}/>

option是echarts配置,详见 http://echarts.baidu.com/option.html#title

3、BUG

// Android 打包后文件不显示
// 将node_modules\native-echarts\src\components\Echarts\tpl.html复制到android/app/src/main/assets下面
// 修改render方法中source
// 如果打包后图表可以上下左右拖动,将scalesPageToFit设为true
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={true}
                    source={{uri: 'file:///android_asset/tpl.html'}}
                    onMessage={event => this.props.onPress ? this.props.onPress(JSON.parse(event.nativeEvent.data)) : null}
                />
            </View>
        );
}

效果展示
react-native-echarts.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 持续更新中...... 一套企业级的 UI 设计语言和 React 实现。 https://mobile.ant....
    日不落000阅读 11,121评论 0 35
  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    wgl0419阅读 11,468评论 1 9
  • 中年女人半信半疑的播通了手里的电话。 一边焦急的来回踱着步,嘴里不停的嘀咕着:“老师快接电话呀,快接电话呀。” 电...
    君子斯如兰阅读 3,110评论 2 1
  • 上天一定会厚待那些勇敢的、多情的人!
    杨小远阅读 2,187评论 0 0
  • 文/房子 老屋要拆迁啦!我以为他会在这里住到最后。 他今年七十二岁,驼背,左眼小时候被国民党陈××的军队弄伤,一米...
    二垚阅读 2,383评论 17 15