gpt4 book ai didi

javascript - 条形图不呈现,Recharts,React

转载 作者:行者123 更新时间:2023-11-30 11:16:58 25 4
gpt4 key购买 nike

我将 RechartsReact 一起使用,我得到以下带有代码的输出,为什么它不在那里显示条形图? (连Bar背景都在渲染)

有什么我缺少导入或添加的吗?

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;

这是我的输出:

enter image description here

最佳答案

从 BMW、Mercedes 的值中删除引号。查看演示 here

关于javascript - 条形图不呈现,Recharts,React,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51191106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com