我有一个简单的 React 组件,它应该使用 highcharts-react 库呈现两个 Highcharts。图表的数据来自父组件的状态,并作为道具传递给该组件。当页面加载时,饼图是空的(例如,只有一个没有系列的空圆圈)。如果我使用 React 元素检查器检查 HighchartsReact 元素,我可以看到正确的数据在 options 属性中。此外,如果我手动更改检查器中的任何数据,图表会突然出现。我的猜测是它与图表没有正确更新有关,但我无法准确确定我做错了什么。
const sharedPlotOptions = {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: null,
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
}
}
},
series: [{
name: 'Countries',
colorByPoint: true,
data: []
}]
}
export function CountryPopulationPlot(props) {
let adultData = props.countries.map(country => ({
name: country.name,
y: country.population //TODO: use adult only data
}))
let allData = props.countries.map(country => ({
name: country.name,
y: country.population
}))
let adultPlotOptions = sharedPlotOptions
adultPlotOptions.series[0].data = adultData
let allPlotOptions = sharedPlotOptions
allPlotOptions.series[0].data = allData
return(
<div>
<HighchartsReact
highcharts={Highcharts}
options={adultPlotOptions}
oneToOne={true}
/>
<HighchartsReact
highcharts={Highcharts}
options={allPlotOptions}
/>
</div>
);
}
编辑: oneToOne 道具是修复错误的尝试,它似乎没有任何效果。
动漫人物
元芳怎么了
相关分类