question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tooltip payload not working in pieChart

See original GitHub issue

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

Tooltip doesn’t show payload’s array

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/).

  1. Visit the API page http://recharts.org/#/en-US/api/Tooltip, copy the payload’s example Use it for a pie chart, which I did in below fiddle http://jsfiddle.net/u172931e/

What is the expected behavior?

It should reflect the value passed in which is payload={[{ name: '05-01', value: 12, unit: 'kg' }]}

Which versions of Recharts, and which browser / OS are affected by this issue? Did this work in previous versions of Recharts?

Windows, Chrome. and latest version of Recharts

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:5

github_iconTop GitHub Comments

1reaction
lunalubracommented, Apr 15, 2021

Let me explain it with more detail. Tooltip componente gets actived when you hover a part of the analytic. While inactive, it does not pass the props you would expect, this, sometimes, causes that when you hover to trigger active state, it, instead of passing the correct props, pass payload and label as undefined or [Array(0)]. To solve this, you need to use the content atribut and pass a react component that will recive the props from the tooltip component. After this, trigger the active state and render the values you want (sometimes is deep nested in the payload array you reicive with the props), in my case: <Tooltip payload={arrayOfCountries} content={props => { console.log(props.payload[0]?.payload?.payload); return ( <div> {props.payload[0]?.payload?.payload?.country}:{" "} {props.payload[0]?.payload?.payload?.value} </div> ); }} /> (Be sure to use some checking if exists operator like the ? or ?? or an if statement in order to access the deep nested content on the payload prop) Disclaimer: This is what i think actually happend, i may be wrong

1reaction
liegecommented, Jan 19, 2019

@havywu
render() { const { active } = this.props;

if (active) {   // **this is your problem**
  const { payload, label } = this.props;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Recharts Piechart - conditionally displaying label on each ...
I have two questions: On mouse hover , I want to show the text with percentage in tooltip. how to get percentage value...
Read more >
Tooltips are not displayed on Bar/Pie Chart widget on the ...
Open a dashboard with a pie chart and a bar chart. Hover over the pie chart. Notice that there are tooltips shown. Move...
Read more >
recharts/recharts - Gitter
API page for tooltip mentioned about payload attribute but i am not able to get it ... does anyone have a working example...
Read more >
Recharts
Quickly build your charts with decoupled, reusable React components. Reliable. Built on top of SVG elements with a lightweight dependency on D3 submodules....
Read more >
recharts.Tooltip JavaScript and Node.js code examples
Tooltip (Showing top 15 results out of 315) ... render() { const {data} = this.props; return ( <PieChart width={400} height={350}> <Pie dataKey="value" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found