首页 > 解决方案 > 如何在 d3.js 中获取没有子元素的元素的工具提示

问题描述

在 D3.js 布局中,工具提示仅对具有子节点的节点可见。

找到我的附加代码 https://codesandbox.io/s/affectionate-thunder-l024x

我有一个对象,其中有些包含孩子,有些则没有。在图表中显示它们时,工具提示仅对其中有子对象的对象可见。

const dataObj = {
  name: "Home",
  children: [
    {
      name: "A",
      metricsValue: "ma",
      children: [
        {
          name: "A-B",
          value: 1.2,
          metricsValue: "ma-mb"
        },
        {
          name: "A-B-C",
          metricsValue: "ma-mb-mc",
          children: [
            {
              name: "A-B-C-D-1",
              value: 2.5,
              metricsValue: "ma-mb-mc-md-1"
            },
            {
              name: "A-B-C-D-2",
              value: 2.566,
              metricsValue: "ma-mb-mc-md-2"
            }
          ]
        }
      ]
    },
    {
      name: "BCD",
      value: "6.5",
      metricsValue: "m1"
    }
  ]
};

标签: javascriptreactjsd3.js

解决方案


推荐阅读