我有一个来自 react-highcharts 的饼图。我目前正在尝试实现向下钻取功能。
如果我删除我的函数,向下钻取工作,所以我怀疑我的函数覆盖了 react-highcharts 的默认 onclick。
以下代码在反应组件中
createPieChartData()
{
var data = []
var steps_array = this.steps
var step
for (step of steps_array)
{
let obj = {}
obj.name = step.position + " " + step.short_name
obj.y = parseInt(step.duration)
obj.drilldown = (parseInt(step.position)-1).toString()
data.push(obj)
}
let series = []
let action
let index = 0
for(action of this.actions)
{
let obj = {}
obj.name = "Step " + index + " Actions"
obj.id = index.toString()
obj.data = action.map(element => {
return [element.action_name, (1/action.length)]
})
series.push(obj)
index+=1
}
const config = {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie',
height: 750
},
title: {
text: 'Duration Breakdown'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
events: {
click: this.showdetailsClick.bind(this)
},
series: {
dataLabels: {
enabled: true,
format: '{point.name}: {point.y:.1f}%'
}
}
},
},
series: [{
name: 'Time',
colorByPoint: true,
data: data
}],
drilldown: {
series: series
}
};
createPieChart()
{
return <ReactHighcharts config = {this.createPieChartData()}></ReactHighcharts>
}
render() {
return (
<div>
<h1> Time Distribution </h1>
<br />
<br />
{this.createPieChart()}
<br/>
{
this.state.showdetails?
<p> <p>{this.displayStepDetails(this.state.step_num)}</p> <br/> <h4>Actions</h4> {this.createTable(this.actions, this.state.step_num)} </p>
:
<div></div>
}
<br/>
<br />
<br />
{this.createTimeSeries()}
<br/>
{}
</div>
);
}
}
感兴趣的线
events: {click: this.showdetailsClick},
位于 plotOptions 的配置变量中
它在我的组件中触发此功能
showdetailsClick (event) {
console.log(event)
if (this.state.showdetails == false)
{
this.setState({
showdetails: true,
step_num: event.point.index,
})
}
else
{
if (event.point.index != this.state.step_num){
this.setState({
step_num: event.point.index,
})
}
else {
this.setState({
showdetails: false,
})
}
}
}
如果我注释掉此函数,则向下钻取按预期工作,否则我的函数被调用并按预期工作,但单击时不会发生向下钻取