使用d3.js开发树状图并为不同属性添加不同颜色

D3.js使用

D3.js的优势 : 相对echarts等可视化库,允许用户通过JavaScript对可视化效果进行深度定制,以满足各种特定需求。

1.官网

官网:https://d3js.org/

github地址: https://github.com/d3/d3/wiki

官方API:https://github.com/d3/d3/blob/master/API.md

2.使用

使用原生Js和d3.js开发树状图

<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  <title>Node-Link Tree</title>
  <script src="https://d3js.org/d3.v7.min.js"></script>
</head>

<body>
  <div id="chart"></div>
  <script>
    //对象中的属性名是灵活的,和js对应即可
    const dataObj = {
     
      label: "R",
      style: {
     
        color: "#000",
        background: "#00ff00"
      },
      children: [
        {
     
          label: "R0",
          style: {
     
            color: "#000",
            background: "#ffff00"
          },
        },
        {
     
          label: "R1",
          style: {
     
            color: "#000",
            background: "#0000ff"
          },
          children: [
            {
     
              label: "R11",
              style: {
     
                color: "#000",
                background: "#ff0000"
              },
            },
            {
     
              label: "R12",
              style: {
     
                color: "#000",
                background: "#00ff00"
              },
            },
          ],
        },
        {
     
          label: "R2",
          style: {
     
            color: "#000",
            background: "#ffff00"
          },
        },
        {
     
          label: "R3"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值