向上钻取时将数据动态添加到 highcharts 的顶层

Add data dynamically to the top level in highcharts when drilling up

我在 highcharts 中使用 asyn drilldown。 当我向下钻取时,我正在调用一个服务来获取数据并更新系列(在向下钻取事件中)

drilldown: function(e) {
  .....
  // Service call to get data for the chart 
  clientObj.getAggData(srcTbl, fields, function(res) {

  // data returned from service is set to the chart series
  chart.addSeriesAsDrilldown(e.point, res);

  }, nextLevel, filterStr);
}

这部分工作正常。当我向上钻取时,我想做类似的事情,因为 well.I 想调用服务并获取必须在图表对象的 'drillup' 事件中完成的顶级系列的数据。

目前正在发生的事情是在我向上钻取时获取存储在 chart.drilldownLevels.series 中的数据。如果我尝试使用 addSeries API,它会在 chart.drilldownLevels.series 中存储的系列之上添加另一个系列。

像 update() 这样的其他 API 也不能正常工作。

您可以使用相同的向上钻取事件并为必要的级别分配值,

events: {
    drillup: function(e) {
      this.options.series[0].data[0] = {
        name: 'Databases',
        y: 20,
        drilldown: 'dbs'
      }
    }
  }

如果要添加新数据点,您应该调用 this.series[0].setData()

this.series[1].setData([{
            name: 'Dieren',
            y: 5,
            drilldown: 'animals'
          }, {
            name: 'Fruit',
            y: 2,
            drilldown: 'fruits'
          }, {
            name: "Auto's",
            y: 4
          }, {
            name: "test's",
            y: 4
          }], false, false);

DEMO

DEMO USING CUSTOM Button