高图表中树图中的选择更改

Selection change in Tree Map in High Chart

jsfiddle link : click here

这里有两个问题需要解决:

问题 1: 单击 selection2 和 selection 3 工作正常,但单击 Selection1 并没有反映更改。

问题二: 对于不同选择的return不同的dataLabel,我已经编写了代码,它似乎工作正常但是在调试时我发现每次进行选择时,以下代码都会执行两次。

formatter: function () {
  if(value=="selection3"){
    return '<b>'+this.point.name + '<br/>'+ this.point.value + '%</b> ' 
  }else{
    return '<b>'+this.point.name + '<br/>'+ this.point.value + '</b> '
  }
},

我的问题是这个格式化程序函数是如何工作的,以及为什么每次选择都执行两次 if 条件。

感谢您的帮助。

根据第 1 期:

正如@ewolden 提到的那样

Issue one is caused by selection1Data being set in the initialization, and updated by reference

要修复它,您可以使用 setData(data [, redraw] [, animation] [, updatePoints]) 方法更新您的数据,将 updatePoints 设置为 false(对于所有系列更改)

$('#selection1').click(function() {
  value = "selection1";
  chart.series[0].setData(selection1Data, true, {}, false);
});

updatePoints (Default: true)

When the updated data is the same length as the existing data, points will be updated instead of replaced. This allows updating with animation and performs better. In this case, the original array is not passed by reference. Set false to prevent.

也使用 setDataupdate

更可取

.. **[update]** method is more performance expensive than some other utility methods like Highcharts.Series#setData or Highcharts.Series#setVisible.


根据第 2 期:

函数formatter 将为将提供的每个系列调用。在您的示例中 chart 包含两个系列,这就是为什么

... everytime a selection is made, following code is executed twice.