reactjs - 防止 Recharts Y 轴标签换行
问题描述
目前我的图表标签正在换行,我想指定一个宽度,以便它们仅在超过该宽度时才换行。现在每个词都是自己的一行,这不是我想要的行为。
<BarChartWrapper>
<BarChart
layout="vertical"
width={668}
height={248}
barCategoryGap={20}
data={data}
margin={{ top: 0, right: 50, bottom: 0, left: 50 }}
>
<CartesianGrid strokeDasharray="5" horizontal={false} stroke="#E7E7E7" />
<XAxis
label="(%)"
// can also pass in a react component label={<CustomizedLabel />}
tickLine={false}
tickMargin={10}
type="number"
domain={[0, 90]}
/>
{/* domain is max gonna be the max agreement + 10*/}
<YAxis
tick={{fontSize: 10, color: Colors.gray2}}
tickLine={false}
tickMargin={20}
dataKey="name"
type="category"
/>
<Tooltip />
<Bar dataKey="uv" barSize={24} fill="#009BAB" radius={[0, 4, 4, 0]} />
</BarChart>
</BarChartWrapper>
解决方案
不幸的是,Recharts YAxis tick
没有whiteSpace
用于自定义属性的tick
属性,但您可以使用属性更改YAxis
宽度width
以增强文本换行问题:
<YAxis
tick={{fontSize: 10, color: Colors.gray2}}
tickLine={false}
tickMargin={20}
dataKey="name"
type="category"
width={300} // ----> here
/>
默认width
值为60
。有关重新图表文档的更多信息。
推荐阅读
- docker - Sitecore 码头工人构建。Invoke-RemoteScript.ps1 超时
- javascript - 使用历史推送重定向用户反应
- java - spring如何触发为ChainedTransactionManager创建JpaTransactionManager bean
- bash - 历史命令未被识别为 child_process 中的内部命令
- python - 从源代码安装python3.6时没有名为venv的模块
- reactjs - 如何在每次重新渲染时改变反应钩子中的状态变量?
- sql - 在sql server中合并行
- android-studio - 在 Android Studio 中隐藏图标并将布局缩放默认设置为 25%
- r - 如何让我的李克特图表从发散变为收敛?
- postgresql - 从 postgresql 上损坏的外键剩余部分中恢复