亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 JS 中迭代 JSON 結構

在 JS 中迭代 JSON 結構

米琪卡哇伊 2021-06-10 14:06:02
我需要設置一些圓的半徑,我有以下數據,由鏈接和節點組成。我需要將圓(節點)的半徑設置為連接到節點的鏈接的總和var data = {    "nodes": [        {            "id": "s1",            "val": 12        },        {            "id": "s2",            "val": 12        },        {            "id": "s3",            "val": 12        },        {            "id": "s4",            "val": 12        },        {            "id": "s5",            "val": 12        },        {            "id": "s6",            "val": 12        }    ],    "Links": [        {            "n1": "s1",            "n2": "s2",            "amount": 10        },        {            "n1": "s2",            "n2": "s3",            "amount": 10        },        {            "n1": "s2",            "n2": "s4",            "amount": 10        },        {            "n1": "s2",            "n2": "s6",            "amount": 10        },        {            "n1": "s3",            "n2": "s1",            "amount": 10        },        {            "n1": "s4",            "n2": "s5",            "amount": 10        },        {            "n1": "s5",            "n2": "s6",            "amount": 10        }    ]};即(我希望節點此時處于上下文中),我在下面編寫了一些偽代碼val1 = 0val2 = 0 for i to len.links  if (links.node1 = nodes.id)    val1 = val1 + links.amount  else if (links.node02 = nodes.id)    val2 = val2 + links.amountnextsum = val1 + val2下面的代碼將圓圈放在屏幕上,我嘗試了各種方法,但結果是我所說的死亡白屏  var w = 1200;  var h = 800;  var svg = d3.select("body").append("svg").attr("width",w).attr("height", h);      var lines = svg.attr("class", "line")  d3.json("data.json", function(error, data) {        console.log(data);        var circles = svg.selectAll("foo")  .data(data.nodes)  .enter()  .append("circle")  .attr("cx", function(d) {    return d.x;  })  .attr("cy", function(d) {    return d.y;  })  .attr("r", 20); // <- i want to put this calculation here我是 JS 新手,不知道如何將其翻譯成 Javascript
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 257 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號