recharts: Dots don't appear

Hello,

I call this 2 Component 2 times from the same function to get 2 identical graphs, only data change :

<ResponsiveContainer>
				<ComposedChart  data={areaLine.slice()} margin={{ top: 10, right: 30, left: 0, bottom: 0 }} stroke="none">
					<XAxis dataKey="name" tick={{ fill: '#ffffff' }} stroke="rgba(255,255,255,.5)"/>
					<YAxis tick={{ fill: '#ffffff' }} stroke="rgba(255,255,255,.5)"/>
					<CartesianGrid strokeDasharray="3 3" stroke="rgba(255,255,255,.5)"/>
					<Tooltip />
					<Area type="monotone" dataKey="Periode actuelle" stroke="#236cb6" strokeWidth={2} fillOpacity={0.3} fill="#44c0ff" activeDot={{ stroke: '#white', strokeWidth: 4, r: 8, fill: '#ff5f4a'}} dot={{ stroke: '#44c0ff', strokeWidth: 4, r: 2, fill: 'blue'}}/>
					<Line type="monotone" dataKey="Periode precedente" stroke="#ff7f78" strokeWidth={2} activeDot={{ stroke: '#white', strokeWidth: 4, r: 8, fill: '#ff5f4a'}} dot={{ stroke: '#44c0ff', strokeWidth: 4, r: 2, fill: 'blue'}} />
				</ComposedChart>
			</ResponsiveContainer>

And the result is :

test

Why dot is only on the last line? and not on both graph and on the Area and Line ?

Thanks in advance šŸ˜„

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 20
  • Comments: 34 (5 by maintainers)

Most upvoted comments

Same issue. Setting isAnimationActive on Line to false also solves it for me. Version: 1.6.2

Hello guys! On #1624 issue, @klarstrup gave a solution that worked for me. Apparently this problem happens in other types of graphic too, as in my case, was using Bar.

The solution, proposed by @klarstrup, was to put a key prop on the BarChart component, so when it changes, the whole graphic will re-render, with all the animations. I just put key={Math.random()}, so he always renders now 😃

@xile611 it persists.

Having the same issue but I don’t want to turn off the animation + I can’t set key={Math.random()} because I toggle lines (show/hide - and the animation is happening only for specific Line) and I don’t want the whole chart to rerender when the data changes.

I think it’s safe to infer this may be a react-smooth issue, so I opened an issue against that repo:

https://github.com/recharts/react-smooth/issues/44

I having a similar issue. If the animation is on, the areas stop drawing. It’s fully drawn if the window resizes. If the animation is off, everything works as expected.

recharts_bug

I magically solved the issue by using useMemo, which might work for your case~

const dataUsedForChart = React.useMemo(() => {
   // Some data transformation here
}, [dataFetchedFromBackend])

I have managed to make it work with animation active. As mentioned before, the key is using the key prop.

const [dataVersion, setDataVersion] = useState(0)

useEffect(() => {
  setDataVersion((value) => value + 1)
}, [data])

return (
  ...
  <Area key={`data-${dataVersion}-area`}
  <Line key={`data-${dataVersion}-line`}
  ...
)

This increments the iteration of data and re-renders with the new key, forcing react to update the chart components. The only downside is that, in case of data change, the chart doesn’t ā€œtransitionā€ but rather draws the line from beginning.

Hello everyone

Please, just add <Tooltip /> below <YAxis /> and set isAnimationActive={false} for <Line />

Worked in my case

I’m having the same issue. It seems to be if the animation is interrupted then the dots don’t get drawn.