简体   繁体   English

使用 ReactJS 进行 D3Plus 可视化

[英]D3Plus Visualization with ReactJS

I'm trying to run the example from this Link , but the only thing I get is a grey box (nothing happens when I click it).我正在尝试从此Link运行示例,但我得到的唯一结果是一个灰色框(单击它时没有任何反应)。 I'm using the d3plus-react package, version 0.5.2 with react version 16.7.0.我正在使用 d3plus-react 包,版本 0.5.2 和版本 16.7.0。 Here is my code:这是我的代码:

import React, { Component } from "react";
import { Treemap } from "d3plus-react";

const methods = {
data: [
    { value: 100, name: "alpha", group: "group 1" },
    { value: 70, name: "beta", group: "group 2" },
    { value: 40, name: "gamma", group: "group 2" },
    { value: 15, name: "delta", group: "group 2" },
    { value: 5, name: "epsilon", group: "group 1" },
    { value: 1, name: "zeta", group: "group 1" }
  ],
  id: ["group", "name"],
  size: "value"
};

class Hierarcy extends Component {
  render() {
    return (
      <React.Fragment>
        <Treemap config={methods} />
      </React.Fragment>
    );
  }
}

export default Hierarcy;

I would appreciate any help :) ps: I forgot to mention that I created the app with create-react-app我将不胜感激 :) ps:我忘了提到我使用 create-react-app 创建了该应用程序

It seems like you have to use groupBy: ["group", "name"] instead of id .似乎您必须使用groupBy: ["group", "name"]而不是id

Unfortunately, the linked Grouped TreeMap visualization is from version 1.0 of d3Plus, you can see here the old examples including the mentioned https://d3plus.org/examples/1.0/ .不幸的是,链接的Grouped TreeMap可视化来自 d3Plus 的 1.0 版,您可以在此处看到旧示例,包括提到的https://d3plus.org/examples/1.0/ d3Plus-react uses version 2.0 of d3Plus and when using the Treemap component you are using d3plus-hierarchy and in this case a gruped visualization looks like this https://d3plus.org/examples/d3plus-hierarchy/getting-started/ , without the interactivity you want on click. d3Plus-react 使用 d3Plus 的 2.0 版,当使用 Treemap 组件时,您使用的是d3plus-hierarchy ,在这种情况下,gruped 可视化看起来像这样https://d3plus.org/examples/d3plus-hierarchy/getting-started/ ,没有您想要点击的交互性。

To show the tooltip with the value in this version it's necessary to pass tooltipConfig configuration.要在此版本中显示带有值的工具提示,必须传递tooltipConfig配置。

const methods = {
  groupBy: ["group", "name"],
  data: [
    { value: 100, name: "alpha", group: "group 1" },
    { value: 70, name: "beta", group: "group 2" },
    { value: 40, name: "gamma", group: "group 2" },
    { value: 15, name: "delta", group: "group 2" },
    { value: 5, name: "epsilon", group: "group 1" },
    { value: 1, name: "zeta", group: "group 1" }
  ],
  tooltipConfig: {
    body: d => `<div>Value: ${d.value}</div>`,
    title: d => `${d.name}`
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM