reactjs - Recharts - 调整 yAxis 笛卡尔网格的位置
问题描述
如何将我的 yAxis 笛卡尔网格调整为位于条形的开头而不是中心,并沿 y 轴延伸到条形区域上方,如第二张图像所示。 点击查看图片
另外,如下图所示,如何显示从一个条到另一个条的斜率?
这是我的代码
<ResponsiveContainer height={250} width={"100%"} >
<BarChart data={data}>
<YAxis
dataKey="total"
tickFormatter={(tick) => {
if(tick >= 1000 && tick < 1000000) return ((tick / 1000) + 'K')
else if (tick >= 1000000)return ((tick / 1000000) + 'M');
else return tick;
}}
label={<AxisLabel>Number of Items</AxisLabel>}
/>
<XAxis dx={-20} dataKey="product" xAxisId={0} tick={{ fontSize: 16 }} dy={10} />
<XAxis dx={-20} dy={-10} orientation="top" xAxisId={1} dataKey="product" tick={{ fontSize: 16 }} />
<CartesianGrid strokeDasharray="8" stroke="#DFE2E6" />
<Tooltip cursor={{ fill: "transparent" }} />
{dataKeys && dataKeys.map((itemKey, idx) =>
<Bar key={itemKey + idx} dataKey={itemKey} fill={colors[idx]} stackId="a" barSize={80}></Bar>)}
</BarChart>
</ResponsiveContainer>
解决方案
您可以使用 y 轴
.recharts-yAxis .recharts-text {
transform: translate(-50px, 0);
}
或者只是添加tick={{ dx: -7 }}
<YAxis
dataKey="total"
tick={{ dx: -7 }}
tickFormatter={(tick) => {
if(tick >= 1000 && tick < 1000000) return ((tick / 1000) + 'K')
else if (tick >= 1000000)return ((tick / 1000000) + 'M');
else return tick;
}}
label={<AxisLabel>Number of Items</AxisLabel>}
/>
推荐阅读
- java - 如何使用 Scanner 解析双打
- python - 在 Python 中打开 xlxs 工作簿,自动文件名
- ios - 为 CollectionViewCell 添加标题
- java - 创建链接列表的链接列表时出错
- selenium - Selenium 如何将文件上传到 Microsoft Edge
- zap - 企业代理背后的 Zap 代理连接问题
- javascript - JavaScript:如何向现有的 JSON 数组添加新项目?
- android - 使用firebase时如何防止暴露业务逻辑?
- shell - 是否可以从单个 jq 调用将多个值输出到不同的文件?
- javascript - 如何停止使用 HTML5 Canvas 进行绘制