I am trying to display value next to legend, but I am getting undefined. Debugged but no luck, can you let me know how to fix it.
Providing my code snippet and stackblitz below
https://stackblitz.com/edit/react-piechart-padding-complete-8jdttg?file=index.js
status_pie_data: [
// {"name":"On Arrival","value":0},
{ name: 'Daily', value: 100 },
{ name: 'Weekly', value: 20 },
{ name: 'Monthly', value: 30 },
{ name: 'One Time', value: 50 },
// {"name":"Active","value":0},
// {"name":"Completed","value":0}
],
<Legend
layout="vertical"
verticalAlign="middle"
align="right"
wrapperStyle={{
fontFamily: 'Lato',
fontWeight: 400,
fontColor: '#000',
fontSize: '9pt',
marginRight: '0px',
}}
formatter={(value, entry, index) => `${entry.name}: ${value}`} // Customize formatter
In order to achieve it you need to use the content prop. the prop needs to return JSX element (can be array). we will use map to loop through the payload and we will render the values we need:
To know what more info you are getting in the content obj you can console log it.
if you console log each item from obj.payload you will see:
and the item.payload is:
I recommend you to console log the data your self and see if you find any other valuable value you can use there.
This method will help you to create your own design for the legend.
If you want to use the formatter prop. the formatter prop is recieving the value only. there for you will need to find inside your
status_pie_dataarraythe object withname === valueand render the info from there. if you want i can edit the answer with a code example