【问题标题】:React Native refusing to work with ChartReact Native 拒绝使用 Chart
【发布时间】:2016-12-29 10:57:58
【问题描述】:

我是 React-Native 的新手,我正在为 Android 开发一个应用程序。我已经尝试实现一个图表...我从这里 https://github.com/tomauty/react-native-chart 安装了 node_module react-native-chart,并且我编写了以下组件,类似于使用中提供的组件图表入门教程的一部分。

import React, {Component, PropTypes} from 'react';
import Button from 'react-native-button';
import Chart from 'react-native-chart';
import {View,
    Picker,
    StyleSheet,
    Text,
    Navigator,
    TouchableHighlight}
    from 'react-native';

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: 'white',
    },
    chart: {
        width: 200,
        height: 200,
    },
});

const data = [[
    [0, 1],
    [1, 3],
    [3, 7],
    [4, 9],
]];

export default class Chart extends Component{

    constructor(){
        super()
    }

    render() {
        return (
            <View style={styles.container}>

                <Chart
                    style={styles.chart}
                    data={data}
                    verticalGridStep={5}
                    type="line"
                    showDataPoint={true}
                    color={['#e1cd00']}
                />

                <Button
                    style={{fontSize: 20, color: 'red'}}
                    styleDisabled={{color: 'red'}}
                    onPress={() => this.props.navigator.pop()}>
                    Back
                </Button>

            </View>
        )
    }

}

每当我从其他组件中单击应该打开 Chart 组件的按钮时,应用程序就会崩溃。如果我从渲染方法中删除图表,组件加载正常,只显示按钮

我该怎么办?

【问题讨论】:

  • 请分享错误的样子
  • @FacundoLaRocca 我只包含了该组件,因为屏幕上没有提供任何错误...当我单击应该启动我的图表组件的按钮时,应用程序崩溃,留下一个对话框说“不幸的是,AppName 已停止。”但是如果我从渲染方法中取出图表,组件就会被加载
  • 你试过我的答案了吗?让我知道它是否有效。
  • 是的,我试过了。我也遇到了同样的事情。
  • @SimpleFuzz 在下面试试我的答案

标签: javascript android node.js react-native


【解决方案1】:

应用程序崩溃,特别是在 Android 中,是由缺少库文件引起的。

npm install react-native-chart --save

没问题,但是这是一个使用本机组件的模块,而不是纯 js 存储库。

您应该使用manual linking 或使用

rnpm 链接 react-native-chart

或者

react-native 链接 react-native-chart

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-25
    • 2018-08-04
    • 2020-11-12
    • 2021-09-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多