【发布时间】:2020-05-17 11:35:22
【问题描述】:
我是 react-google-charts 的新手,我正在开发一个半馅饼甜甜圈,但尽管成功了,但我遇到了一个问题,这个问题是可见半馅饼的百分比总和仅为 50 % 因为其他 50% 被隐藏了。
我怎样才能使可见部分达到 100%?
这里有图表的代码:
import React, { Component } from "react";
import { Chart } from "react-google-charts";
class PieChart extends Component {
constructor(props) {
super(props);
this.props = props;
this.state = {
loaded: false
};
}
componentDidMount() {
this.setState(
{
loaded: true
},
() => {
this.setState({
width: document.querySelector("#container").getBoundingClientRect()
.width
});
}
);
}
render() {
return (
<div>
{this.state.loaded ? (
<div id="container">
<Chart
width={this.state.width}
height={"400px"}
chartType="PieChart"
loader={<div>Loading Chart</div>}
data={this.props.data}
options={{
backgroundColor: "transparent",
title: "Distribución de posesiones",
// Just add this option
pieHole: 0.4,
pieStartAngle: 270,
slices: {
4: {
color: "transparent"
}
}
}}
/>
</div>
) : (
"Cargando datos"
)}
</div>
);
}
}
module.exports.PieChart = PieChart;
如您所见,可见部分的总和只有 50% 而不是 100%。
那么,我怎样才能使可见部分占总数的 100%?
你可以在这里查看所有代码:
【问题讨论】:
-
我能看到的唯一方法是我们可以通过在 react 中使用 refs 更改 dom 操作来实现。意味着我们自己会覆盖切片中的百分比。数据是固定的还是会改变?如果您的数据再次更改,您似乎会错过甜甜圈形状。
-
数据由google-charts计算。我不知道如何修改标签的值
标签: javascript reactjs charts react-google-charts