简体   繁体   English

图表-右对齐堆叠条形图时看不到标签

[英]ReCharts - not able to see label when right aligned for stacked bar chart

I am creating an example of StackBarChart using Recharts library but I am not able to see the label when it's position is set to "right" though I am able to show the other label positions. 我正在使用Recharts库创建StackBarChart的示例,但是当它的位置设置为"right"虽然我能够显示其他标签的位置,但我看不到标签。

<BarChart width={400} height={300} data={data} layout="vertical">
   ...
   <Bar dataKey="pv" stackId="a" barSize={15} radius={[20,20,20,20]} fill="#8884d8" background={{fill: "#ddd", radius: [20,20,20,20]}} tick={false} />
   <Bar dataKey="uv" stackId="a" barSize={15} radius={[20,20,20,20]} fill="#aaa" >
     <LabelList dataKey="name" position="right" />
      {/* works fine <LabelList dataKey="name" position="top" /> */}
   </Bar>
</BarChart>

Here is the Jsfiddle (updated). 这是Jsfiddle (已更新)。

I have updated your fiddle script here . 在这里更新了你的小提琴脚本。

You have to provide a correct dataKey field to LabelList , and put LabelList as a child of Bar component 你必须提供正确的dataKeyLabelList ,并把LabelList作为一个孩子Bar成分

UPDATED: 更新:

New jsfiddle , you need margin in your case. 新的jsfiddle ,您需要margin So that the SVG reserved some spaces aside of the chart for additional text. 因此,SVG在图表旁边保留了一些空格以用于其他文本。 NOTE that it is the margin props of the chart, not the margin from CSS style. 请注意,它是图表的margin 道具 ,而不是CSS样式的margin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM