首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Recharts -在左侧对齐轴标签

Recharts -在左侧对齐轴标签
EN

Stack Overflow用户
提问于 2018-06-13 18:28:32
回答 1查看 4.9K关注 0票数 1

我正在使用recharts库创建一个水平条形图。我想在左侧对齐y轴标签。

代码语言:javascript
复制
<BarChart width={400} height={300} data={data} layout="vertical" margin={{right: 40}}>
   <XAxis hide axisLine={false} type="number"/>
   <YAxis dataKey="name" type="category" axisLine={false} tickLine={false} />
   <Bar dataKey="pv" stackId="a" barSize={15} radius={[20,20,20,20]} fill="#8884d8" background={{fill: "#eee", radius: [20,20,20,20]}} tick={false} />
   <Bar dataKey="uv" stackId="a" barSize={15} radius={[20,20,20,20]} fill="#eee" >
     <LabelList dataKey="amt" position="right" />
   </Bar>
</BarChart>

Jsfiddle

EN

回答 1

Stack Overflow用户

发布于 2019-06-17 16:51:51

您可以通过使用自定义Tick组件来完成此操作。

代码语言:javascript
复制
const CustomYAxisTick = React.createClass({
    render() {
        const { x, y, payload } = this.props;
        return (<g transform={`translate(${0},${y})`}>
            <text x={0} y={0}
                textAnchor="start"
                fill="#666">{payload.value}</text>
        </g>)
    }
})

然后你可以在你的YAxis中使用它:

代码语言:javascript
复制
<YAxis tick={<CustomYAxisTick />} />

我派生了你的JSFiddle并添加了这些更改。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50834913

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档