recharts: Labels shomtimes not show
Do you want to request a feature or report a bug?
bug
What is the current behavior?
Some times i dont see label

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar (template: http://jsfiddle.net/qbmg1567/).
const _dataTypesMap = {
"0": () => <Bar dataKey="clientQuestions" fill="#6aafff" minPointSize={1} />,
"1": () => <Bar dataKey="arPercent" fill="#b8e986" minPointSize={1} label={{ fill: 'red', fontSize: 20, dataKey: "nps" }}/>,
"2": () => <Bar dataKey="awsPercent" fill="#f16c97" minPointSize={1} />
};
const _getCharts = (dataTypes) => {
return dataTypes.map(t => _dataTypesMap[t]())
};
const DashboardChart = ({ stats, dataTypes }) => {
return (
<BarChart width={1008} height={200} data={stats}
margin={{ top: 5, right: 5, left: 5, bottom: 5 }}>
<Tooltip content={<_Tooltip/>} payload={stats}/>
{ _getCharts(dataTypes) }
</BarChart>
)
};
What is the expected behavior?
I want see all times label
Which versions of Recharts, and which browser / OS are affected by this issue? Did this work in previous versions of Recharts?
rechart - 1.0.0-alpha.1 OS Ubuntu 16.04 - 64x Browser Firefox 56.0b1 (64-бит)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 14
- Comments: 44 (1 by maintainers)
Commits related to this issue
- Workaround for labels not showing:https://github.com/recharts/recharts/issues/829 — committed to darkosancanin/crypto_in_the_black by darkosancanin 5 years ago
I am still using
isAnimationActive={false}Which allows my labels to be rendered. I left myself this comment:
//should be able to remove this prop, I think there is a bug in Pie stopping labels from rendering. This is a temp fix.So it looks like I made a note of the issue, and moved onto something else!
Hit the same issue, have some additional data points.
datais defined in a constant at the top of the file, thelabelmethod is called and the labels are displayeddatavalue is passed as a prop value, thelabelmethod is never called and the labels are not displayed.Edit: Since it works when the data is defined as a variable at the top of the file, one work around is to define an empty variable and mutate it based on the passed props:
it still persists on v1.8.5, not sure why it was closed
This is still an issue why this is closed?
I think it was something like this…
inside render function (doesn’t work)
outside render function (does work)
When the graph data is in the state of the component before render it seems to work.
@totaki I can’t reproduce the bug that you’re saying in the jsfiddle, I can see the label all the time. If you load data via ajax try set prop of
isAnimationActiveBooleanto false.Hi, has there been a fix to the labels other than having isAnimationActive false? I am currently using recharts 1.1.0 and it still fails to display the labels if I hover to quickly over the chart on initial load
In React 16.9.0 Label works well when wrapped with React.memo e.g:
const chart = Rect.memo((props) => <MyBarchart {...props}>, (prevProps, nextProps) => Immutable.is(Immutable.fromJS(nextProps.data), Immutable.fromJS(prevProps.data)) )This issue continues to happen, I’m currently in the latest version, version
2.0.4. To make the labels always show I need to pass the propisAnimationActive={false}to thePiecomponent. It would be nice to re-open this issue.I only found a workaround that you always rerender no mattter what by adding
key="makeid()"to theResponsiveContainer. That solved my problem until it’s fixed.Have the same issue, why this issue is closed?
rechart-‘2.1.14’ version, bug still there. when use data for chart is work well, but if fetch data from API labels of chart not show
The animation problems have been discussed across various issues.
It stems from
recharts/react-smooth: https://github.com/recharts/react-smooth/issues/44I am also facing the same issue. Labels do not render on initial render. It works fine when animation is disabled but I would like to have both animation and labels.
Hi, I have same issue. I used hooks like this and it works well.
The JS filddle doesnt work, nothing is rendered, nevermind the labels. I have intermittent display issues. When my home page loads, there is no animation and no labels. When I change state, unrelated to the pie chart (not passing the changing state as props to the chart), the chart seems to reanimate and display the labels. It seems its only the initial render where the animation has stopped working and the labels are not shown.
I am using react 16.2.0, recharts 1.0.0-beta.6
It used to work on react 15.6.2 and recharts 0.22.4
I am using a function to return my label
The function is not called on the initial render…
In case you did not read the forementioned issue like me, try to check if you are not in this situation :
Fixing the parent rerender during the animation worked for me 🥳
I found a good workaround for this problem. You can render the bar label directly in the Bar component of the chart. and chart labels will be rendered along with the columns. And yes, in the rendering of the columns you can get their values from props with passed in CustomBar key. in my example it is a barDataKey
here is code example
custom bar:
bars config:
method for rendering bars:
onAnimationEnd={()=>{this.setState({});}}this seems to have done the trick !A solution/workaround I came up with is to protect the chart component from unnecessary rerenders by memomising the props, where that upstream rerender is unavoidable. This avoids the need to disable or override animation props.
or more succinctly;
If you only need a shallow compare you can omit the second argument,
I found out for me, in my components, although the Labels seems to not be rendered, actually when I check the Component-Tree, the LabelList and Labels exist. But the size of the LabelList is 0px 0px, so I can’t see them. Maybe there is a chance to add a check to the LabelList-Component.
doesn’t work when adding legend along with tooltip.
isAnimationActive={false}works for <Bar />, Recharts 2.0.8Hit something similar here today
Also having a weird issue with this for barchart. At first I had my constant graph data defined in the render function itself, the labels didn’t show up unless I disabled animation. Moved my graph data outside of the render function and it started to work.