【发布时间】:2018-05-16 18:53:27
【问题描述】:
我正在尝试使用 reChart 渲染条形图以使其 100% 适合其容器:
http://recharts.org/#/en-US/api/ResponsiveContainer
<div className="question">
<div className="question-container">
<ResponsiveContainer width="100%" height="100%">
<BarChart layout="vertical" data={rows}
margin={{top: 5, right: 30, left: 20, bottom: 5}}>
<YAxis axisLine={false} tickLine={false} width={400} dataKey="name" type="category">
</YAxis>
<Bar dataKey="valuePre" fill="#00a0dc" label={<Text scaleToFit={true} verticalAnchor="middle" />}/>
<Bar dataKey="valuePost" fill="#c7c7c7" label={<Text verticalAnchor="middle" />}/>
</BarChart>
</ResponsiveContainer>
</div>
</div>
当我添加 ResponsiveContainer 组件时,数据停止呈现。而当我取出 ResponsiveContainer 并设置 BarChart 组件的宽度和高度后,我又可以看到条形图了。
谁能帮我找出我做错了什么?
这是一个问题:
【问题讨论】:
-
看看你的控制台,你有很多未捕获的引用。
-
除了下面的答案之外,请确保您使用整数而不是像“100px”这样的字符串提供宽度和/或高度。为什么 Re(act)charts 决定完全放弃 Reacts 提供宽度和高度的惯用方式,这超出了我的理解。
标签: javascript css reactjs