反应组件TypeError问题

时间:2018-07-26 09:32:06

标签: javascript reactjs react-redux react-component

我已经安装了反应图组件并将其导入到我的项目中。但是导入后,出现以下错误:

enter image description here

对这个问题有帮助吗? 我有以下代码:

import PropTypes from "prop-types";
import { connect } from "react-redux";
import React, { Component } from "react";
// import LineChart from 'react-chartjs';
// import { Sparklines, SparklinesBars } from 'react-sparklines';
import Chart from "react-google-charts";

class AnalyticsPage extends Component {
    render() {
        const data = [
            ["Year", "Visitations", { role: "style" }],
            ["2010", 10, "color: gray"],
            ["2020", 14, "color: #76A7FA"],
            ["2030", 16, "color: blue"],
            [
                "2040",
                22,
                "stroke-color: #703593; stroke-width: 4; fill-color: #C5A5CF"
            ],
            [
                "2050",
                28,
                "stroke-color: #871B47; stroke-opacity: 0.6; stroke-width: 8; fill-color: #BC5679; fill-opacity: 0.2"
            ]
        ];

        return (
            <div>
                Analytics
                <div>
                    <Chart chartType="BarChart" width="100%" height="400px" data={data} />
                </div>
            </div>
        );
    }
}

const AnalyticsPageWithRedux = connect()(AnalyticsPage);
export default AnalyticsPageWithRedux;

1 个答案:

答案 0 :(得分:0)

在渲染返回中,您仅提供“ Analytics”,这实质上是提供非实例化的Analytics类。像使用Chart一样使用JSX

return (
        <div>
            <Analytics />
            <div>
                <Chart chartType="BarChart" width="100%" height="400px" data={data} />
            </div>
        </div>
    );

或者如果您希望包装包含图表组件的div:

return (
        <div>
            <Analytics>
                <div>
                    <Chart chartType="BarChart" width="100%" height="400px" data={data} />
                </div>
            </ Analytics>
        </div>
    );