首页 > 解决方案 > 如何将使用一个数据集的工具提示添加到使用 d3 中的另一个数据集的图表中

问题描述

我有一个和弦图,它的值是不可见的,因为值太小了。因此,我们决定将数据集更改为下边框 1% 以进行显示,并将原始值显示为工具提示。这样每个不是“0”的数据集都会被显示出来。现在我很难让工具提示使用 d3 中的第二个数据集。它适用于一个数据集。

function mousemove(p) {
      var a = d3.select(this);
      a.attr("fill-opacity", 1);
      var d = d3.select(this).data()[0];
      const toolTipText = '<b><span style= "color: ' + a.attr('sourceColor') + '">' + a.attr('sourceName') + '</span></b>: ' + d['source']['value']
        + '<hr>'
        + '<b><b><span style= "color: ' + a.attr('targetColor') + '">' + a.attr('targetName') + '</b>: ' + d['target']['value'];
      div
        .html(toolTipText)
        .style("left", p.clientX - 50 + "px")
        .style("top", p.clientY - 80 + "px");
    }

有人可以帮忙吗?

标签: typescriptd3.js

解决方案


推荐阅读