向上钻取时,将数据动态地添加到图表的顶层

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

本文关键字:添加 动态 钻取 数据      更新时间:2023-09-26

我在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);
}

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

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

其他api如update()不能正常工作

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

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);

演示使用自定义按钮