简体   繁体   中英

Bars not rendering, Recharts, React

I am using Recharts with React , I am getting following output with code, why is it not displaying bars over there? (even Bar background is rendering)

Is there anything, i am missing to import or add?

import React, { Component } from 'react';
import { BarChart, Bar, XAxis, YAxis, Tooltip, CartesianGrid, Legend, Line, LineChart } from 'recharts';


class App extends Component {
    cursorStyle = {
        fill: 'white'
    };
    data = [
        { Year: "1929", BMW: "1889", Toyota: "9547", Mercedes: "4881"},
        { BMW: "6548", Mercedes: "8096", Toyota: "4741", Year: "1930"},
        { Year: "1931", BMW: "5013", Toyota: "6269", Mercedes: "3908"},
        { Year: "1932", BMW: "2468", Toyota: "9858", Mercedes: "1623"},
        { Year: "1933", BMW: "3364", Toyota: "5595", Mercedes: "8638"},
        { Year: "1934", BMW: "2032", Toyota: "2570", Mercedes: "8041"}
    ];
    render(){
        return (
            <BarChart
                width={600}
                height={300}
                data={this.data}
                margin={{top: 5, right: 30, left: 20, bottom: 5}}>
                <XAxis type="category" dataKey="Year"/>
                <YAxis type="number"/>
                <Tooltip cursor={false}/>
                <Legend />
                <Bar dataKey="BMW" stroke="#8884d8" fill="#8884d8" background={{ stroke: '#eee' }} isAnimationActive={true} barSize={20}/>
                <Bar dataKey="Mercedes" stroke="#82ca9d" fill="#82ca9d" background={{ stroke: '#eee' }} isAnimationActive={false} barSize={30}/>
            </BarChart>
        )
    }
}

export default App;

Here is my output:

在此输入图像描述

Remove quotes from values of BMW, Mercedes. See the demo here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM