我在 React 中使用 Highcharts,无法阻止树形图节点的默认展开/折叠单击行为。我尝试了几种方法,但没有任何效果。请参阅下面的代码片段,了解我所尝试的详细信息。我已经尝试了 allPointSelect 和单击属性之间的所有组合。
const series = [{
type: "treegraph",
data: [...],
// I've tried setting allowPointSelect to true in combination
// with the point.event.click e.preventDefault()
// and returning false without success.
// I've also left allowPointSelect false without any success.
allowPointSelect: true,
point: {
events: {
click: (e) => {
//I've tried different combinations of the 2 lines below without success
e.preventDefault();
return false;
}
}
}
}]
不幸的是,Highcharts 中没有任何选项可以阻止展开/折叠功能的发生。为了让它工作,你需要写一个包装。
Highcharts.wrap(Highcharts._modules['Series/Treegraph/TreegraphPoint.js'].prototype, 'toggleCollapse', function(proceed, a, flag) {
if (flag) {
proceed.apply(this, Array.prototype.slice.call(arguments, 1));
}
});
文档: https://www.highcharts.com/docs/extending-highcharts/extending-highcharts