【问题标题】:AMCharts - Dynamically add children to tree mapAMCharts - 将子项动态添加到树状图
【发布时间】:2020-11-02 21:01:35
【问题描述】:

我非常喜欢 AMChart 的许多功能,但我找不到任何方法将一些子动态添加到树形图中。

我正在尝试为每个元素加载额外的子元素

  for (var i = 0; i < this.maxDepthLevel; i++) {
    const series = this.chart.seriesTemplates.create(i);
    series.columns.template.events.on("hit", async function(ev) {
      const data = ev.target.dataItem.dataContext;
      children = await api.getChildrenOf(data.id);
      ev.target.dataItem.treeMapDataItem.children.values.push(...children);
    });
  }

^ 这不起作用,当这样做然后缩小时,我得到了

我什至尝试更改基础数据然后调用

  this.chart.invalidateRawData();

但无济于事。

有没有人有将这种动态的孩子添加到树状地图的经验? 我不能简单地预先加载所有内容,不幸的是,可能的深度层太多了,请求也会太大!

【问题讨论】:

    标签: amcharts treemap


    【解决方案1】:

    您需要这样做,而不是直接将子项推送到子值:

    for(var index=0; index < children.length; index++){
        var newChildDataItem = new am4charts.TreeMapDataItem();
        newChildDataItem.value = children[index].value;
        newChildDataItem.name = children[index].name;
        newChildDataItem.color = ev.target.dataItem.dataContext.color;
        ev.target.dataItem.dataContext.children.insert(newChildDataItem);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-08
      • 2013-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多