score:6
This can be achieved by using the Pie
activeShape render-prop, in combination with the Sector
component.
Here is a simplified example which demonstrates this:
import React, { useState, useCallback } from "react";
import { ResponsiveContainer, PieChart, Pie, Sector } from "recharts";
import "./styles.css";
const data = [
{
name: "Group A",
value: 400
},
{
name: "Group B",
value: 300
},
{
name: "Group C",
value: 300
},
{
name: "Group D",
value: 200
},
{
name: "Group E",
value: 278
},
{
name: "Group F",
value: 189
}
];
const renderActiveShape = props => {
const RADIAN = Math.PI / 180;
const {
cx,
cy,
innerRadius,
outerRadius,
startAngle,
endAngle,
midAngle
} = props;
const sin = Math.sin(-RADIAN * midAngle);
const cos = Math.cos(-RADIAN * midAngle);
const sx = cx + (outerRadius - 40) * cos;
const sy = cy + (outerRadius - 40) * sin;
return (
<Sector
cx={sx}
cy={sy}
innerRadius={innerRadius}
outerRadius={outerRadius}
startAngle={startAngle}
endAngle={endAngle}
fill="red"
/>
);
};
export default function App() {
const [activeIndex, setActiveIndex] = useState(null);
const onMouseOver = useCallback((data, index) => {
setActiveIndex(index);
}, []);
const onMouseLeave = useCallback((data, index) => {
setActiveIndex(null);
}, []);
return (
<ResponsiveContainer width="100%" height={250}>
<PieChart height={250}>
<Pie
activeIndex={activeIndex}
data={data}
dataKey="value"
nameKey="name"
cx="50%"
cy="50%"
outerRadius={50}
fill="#8884d8"
activeShape={renderActiveShape}
onMouseOver={onMouseOver}
onMouseLeave={onMouseLeave}
/>
</PieChart>
</ResponsiveContainer>
);
}
Source: stackoverflow.com
Related Query
- Recharts Pie chart .. can pie slice move when selected?
- recharts pie chart w/ value labels inside
- recharts pie chart centering using responsive container
- Recharts render pie chart vertically
- Accessing a slice of a react-chartjs Pie chart
- How can I prevent material-ui Select options to be opened when clicking on particular area of the selected option
- Material React Select Multiple: How i can remove from my array when i click in a selected element?
- can we pass a value when we move to next component using this.props.history.push("/next Component")?
- Recharts scatter chart shows the lowest x value in tooltip when chart is resized
- Recharts chart not updating when using setInterval to periodically append new data
- Pie Chart in Ant Design Charts don't have option to show label by percentage . How can i do it manually?
- how can i call selected item into model when i click on button in react?
- ReactJS - How can I correlate my data in td tags to move when th tag order is moved in my table?
- How can I get my add function to only change contents of the selected index when editing state is true?
- How to make a floating label which can move up when focus or has content in React?
- How can I move a column to a row when UI changes screen/size?
- How can I fetch data from API url into my reactgoogle pie chart in reactjs
- Can anyone help me move data from an Axios JSON response to a plot points on a Chart js line chart?
- How can I add a gap between the bars in Recharts Bar chart (vertical, stacked)
- Material ui load select option data list from server response but when select a option can not return selected value
- Can not have more then 7 numbers in Pie Chart from Apex Charts
- How can we upload multiple files using React.JS ? When we click on the upload button all the names of the selected files must appear
- Can I style the active state of an option when it's selected and disabled using react-select?
- How can I get the input selected on a Autocomplete field when onKeyPress
- How can I fix jsx-a11y/anchor-is-valid when using the Link component in React?
- Can I avoid forceUpdate() when using React with Backbone?
- Set height and width for responsive chart using recharts ( Barchart )
- Invalid hook call. Hooks can only be called inside of the body of a function component when apply style to class base component with material-ui
- react-bootstrap how to collapse menu when item is selected
- When working with lists and keys in React, can Keys contain whitespace/spaces?
More Query from same tag
- Dynamically adding button to div ReactJS?
- React: Redirect to an error page with error message/stack trace using React Router
- Access staticContext through hook in react-router
- I am trying to save data in database but facing error
- How to render props in react components while using react-router-dom version 6
- Obtain selection start, end, and selection value from Material UI's TextField
- How to create an array outside class component or reference state sibling to next sibling React.js
- how to catch react router change event from outside page
- Why can't I get it as an object (abonnes) from result Getelementbyid?
- Creating a button in react that, when clicked, opens a webpage
- How to fill color to Html?
- Implementing SignalR on my React App
- How to import a react file
- React Hook Form - Multiple Rerender
- Uncaught TypeError: Cannot destructure property 'connectWallet' of 'useContext(...)' as it is undefined at Welcome (Welcome.jsx)
- React Incorrect render when combine withRouter/withStyles and mobx's observer
- Implement Circular progress bar using Recharts
- How process data send from a .findAll(include: {all: true}) of sequelize
- React Native App always opening on the login screen
- How to call internal API from Rails view (for ReactJS prerender purpose)?
- Refresh display reactjs when changes the json file
- Fileinput not defined
- ReactiveVar not re-rendering React component
- React, Typescript, and a setState({ [name]: value }) error
- How to make FieldGroup type: file multiple react bootstrap
- Accessing Store's State in Redux From Within A Reducer Function
- react facing issues to find out specific data from an array of objects
- react-router basename not working properly
- Calling dynamic component in React JS
- How to toggle from another js file in React.js