Проблема:
Я создал круговую диаграмму, используя библиотеку recharts.Там я использую PolarRadiusAxis, но он ничего не показывает на графиках.Вот как я организовал свой код.
import React, { Component } from "react";
import { bindActionCreators } from "redux";
import { connect } from "react-redux";
import { Card, CardBody, CardTitle, CardFooter } from "reactstrap";
import {
PieChart,
Pie,
ResponsiveContainer,
Cell,
Tooltip,
PolarRadiusAxis
} from "recharts";
import "./SubscribersByChannelCategory.css";
import { get_device_width } from "../../../actions";
const data01 = [
{
name: "Kids",
value: 35020
},
{
name: "Local",
value: 306017
},
{
name: "None Catgory",
value: 295730
},
{
name: "Sports",
value: 196057
},
{
name: "Entertainment",
value: 173479
},
{
name: "Infotainment",
value: 173029
},
{
name: "Religious",
value: 122779
},
{
name: "Movies",
value: 108054
},
{
name: "News",
value: 92726
},
{
name: "Music",
value: 91975
}
];
const COLORS = [
"#65d3da",
"#79d69f",
"#fad144",
"#d76c6c",
"#138185",
"#26a0a7",
"#ec983d",
"#cbe989",
"#f9ec86",
"#ebf898"
];
class SubscribersByChannelCategory extends Component {
constructor(props) {
super(props);
this.getDeviceWidth = this.getDeviceWidth.bind(this);
}
componentDidMount() {
this.getDeviceWidth();
window.addEventListener("resize", this.getDeviceWidth);
}
getDeviceWidth() {
this.props.get_device_width();
}
render() {
let innerRadius = "50%";
let outerRadius = "90%";
let yaspect = 6.0;
if (this.props.device >= 1024) {
outerRadius = "95%";
innerRadius = "70%";
yaspect = 5.7971;
}
if (this.props.device >= 1666) {
outerRadius = "90%";
innerRadius = "60%";
yaspect = 7.297;
}
return (
<div>
<Card className="subscribers-by-channel-category-card">
<CardTitle className="subscribers-by-channel-category-card-title">
Subscribers by Channel Category
</CardTitle>
<CardBody>
<ResponsiveContainer
width="100%"
height="100%"
aspect={5.0 / yaspect}
>
<PieChart>
<PolarRadiusAxis
type="category"
cursor="pointer"
/>
<Pie
data={data01}
nameKey="name"
dataKey="value"
fill="#8884d8"
innerRadius={innerRadius}
outerRadius={outerRadius}
labelLine={false}
cursor="pointer"
>
{data01.map((entry, index) => (
<Cell fill={COLORS[index]} key={index} />
))}
</Pie>
<Tooltip content={<CustomTooltip />} />
</PieChart>
</ResponsiveContainer>
<CardFooter className="subscribers-by-channel-category-footer">
<div>Bring the cursor near to see the details</div>
</CardFooter>
</CardBody>
</Card>
</div>
);
}
}
function mapDispatchToProps(dispatch) {
return bindActionCreators({ get_device_width }, dispatch);
}
function mapStateToProps(state) {
return {
device: state.device
};
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(SubscribersByChannelCategory);
const CustomTooltip = ({ active, payload }) => {
if (active) {
return (
<div className="subscribers-by-channel-tooltip">
<p className="subscribers-by-channel-tooltip-title">
{payload[0].name}
</p>
<p className="subscribers-by-channel-tooltip-label">{`Channel Category : ${
payload[0].name
}`}</p>
<p className="subscribers-by-channel-tooltip-intro">{`Subscribers : ${
payload[0].value
}`}</p>
<p className="subscribers-by-channel-tooltip-data">
{`Share : ${payload[0].value}`}
</p>
</div>
);
}
return null;
};
Я ищу в Интернете решение этой проблемы, но мне не удалось найти хорошее решение, которое бы помогло моей проблеме.Может ли кто-нибудь помочь мне решить эту проблему?Спасибо.