我们应该如何在 Kendo-react-charts 中使用 reactJs 在圆环图的孔中插入文本。在文档中显示了它,但它在现实中不起作用。文档链接:https ://www.telerik.com/kendo-react-ui/components/charts/series-types/donut/#toc-using-drawing-visuals
我的代码:
import React, { Component } from 'react';
import 'hammerjs';
import { Chart, ChartLegend, ChartSeries, ChartSeriesItem, ChartSeriesLabels } from '@progress/kendo-react-charts';
const donutCenterRenderer = () => (<span>22.5%</span>);
const labelContent = (e) => (e.category);
class Donut extends Component {
constructor(props) {
super(props);
}
render() {
return(
<div className = "container">
<Chart seriesColors={['#050594', '#0E0EC3', '#4343DD', '#8181D9', '#B4B4E1', 'white']}>
<ChartSeries SeriesLabelsPosition = "center">
<ChartSeriesItem type = "donut" data = {this.props.data} categoryField = "kind" field = "share" holeSize={50}>
</ChartSeriesItem>
</ChartSeries>
<ChartLegend visible = {true} labels = "black" position = "bottom"/>
</Chart>
<h5>Donut chart</h5>
</div>
);
}
}
export default Donut;
和作为道具传递的数据:
data: [ {
"kind": "Hydroelectric", "share": 0.175,
}, {
"kind": "Nuclear", "share": 0.238
}, {
"kind": "Coal", "share": 0.118
}, {
"kind": "Solar", "share": 0.052
}, {
"kind": "Wind", "share": 0.225
}, {
"kind": "Other", "share": 0.192
} ]