首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用react-google-charts和react原生呈现甘特图?

如何使用react-google-charts和react原生呈现甘特图?
EN

Stack Overflow用户
提问于 2017-11-27 16:54:14
回答 1查看 1.5K关注 0票数 0

这是我当前版本的包

代码语言:javascript
运行
复制
react-google-charts 1.5.5
react 16.0.0-beta.5
react-native https://github.com/expo/react-native/archive/sdk-22.0.1.tar.gz

现在我正在尝试绘制甘特图(示例可以在herehere中找到)

下面是我当前的代码

代码语言:javascript
运行
复制
import React, { Component } from 'react';
import { View, ScrollView, Text } from 'react-native';
import { Card, Avatar } from 'react-native-elements';
import { Chart } from 'react-google-charts';

class ScheduleScreen extends Component {

    constructor(props) {
        super(props);
        this.state = {
            rows: [
                ['Research', 'Find sources', new Date(2015, 1, 1, 8, 0, 0), new Date(2015, 1, 5, 8, 0, 0), null, 100, null],
                ['Write', 'Write paper', null, new Date(2015, 1, 9, 12, 0, 0), 259200000, 25, 'Research,Outline'],
                ['Cite', 'Create bibliography', null, new Date(2015, 1, 7, 8, 0, 0), 86400000, 20, 'Research'],
                ['Complete', 'Hand in paper', null, new Date(2015, 1, 10, 8, 0, 0), 86400000, 0, 'Cite,Write'],
                ['Outline', 'Outline paper', null, new Date(2015, 1, 6, 8, 0, 0), 86400000, 100, 'Research'],
        ],

            columns: [
                {
                    id: 'Task ID',
                    type: 'string',
                },
                {
                    id: 'Task Name',
                    type: 'string',
                },
                {
                    id: 'Start Date',
                    type: 'date',
                },
                {
                    id: 'End Date',
                    type: 'date',
                },
                {
                    id: 'Duration',
                    type: 'number',
                },
                {
                    id: 'Percent Complete',
                    type: 'number',
                },
                {
                    id: 'Dependencies',
                    type: 'string',
                },
            ],
        };
    }

    onButtonPressClose = () => {
        this.props.navigation.navigate('Home');
    }

    render() {
        return (
            <View>
            <ScrollView>
                <Card title="Schedule">
                    <Chart
                        graph_id="ganttchart"
                        chartType="Gantt"
                        columns={this.state.columns}
                        rows={this.state.rows}
                        chartPackages={['gantt']}
                        width="100%" height="9999px"
                    />
                </Card>
            </ScrollView>
            <View style={styles.buttonBackContainer}>
            <Avatar
                medium
                rounded
                backgroundColor="#66ff33"
                icon={{ name: 'chevron-left' }}
                onPress={this.onButtonPressClose}
            />
            </View>
            </View>
        );
    }
}

const styles = {
    buttonBackContainer: {
        position: 'absolute',
        top: 20,
        left: 20,
        right: 20,
        flexDirection: 'row',
        justifyContent: 'flex-start'
    }
};

export default ScheduleScreen;

每次启动应用程序时,我都会遇到错误

错误

代码语言:javascript
运行
复制
Body:
{"message":"TransformError: 
/Users/ling/workspace/chartapp/node_modules/react-google-
charts/lib/index.js:
[BABEL]/Users/ling/workspace/chartapp/node_modules/react-google-
charts/lib/index.js:Unknown 
option:/Users/ling/workspace/chartapp/node_modules/react-google-
charts/react/react.js.Children.Check out http://babeljs.io/docs/usage/options/
for more informations about options. \n\nA common cause of this error is the presence of a configuration options object without the corresponding preset name.
Example: \n\nInvalid: \n `presets: [{option: value}]}....

我应该如何排除这个错误?在编写代码时,我没有看到任何lint错误。

感谢您的帮助和建议。

EN

回答 1

Stack Overflow用户

发布于 2018-05-11 02:31:22

您发布的错误消息一直引用react-google-charts中的错误。

我不认为它支持react-native,只支持react。我在github上发现了这个问题,似乎有人也有同样的问题,will this work with react native?。另外,react-google-charts npm页面也没有提到react-native。也许可以看看这个question,找到一个替代的库。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47506976

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档