在d3.js中嵌入json文件 [英] embed json file within d3.js

查看:150
本文介绍了在d3.js中嵌入json文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://bl.ocks.org/mbostock/4339083 我正在使用此

而不是 d3.json(/ d / 4063550 / flare.json,function(error,flare){



如何使用html中的json文件,例如我有

  var jsonData = [{
name:A,
children:[
{name:A1,children:[ {name:A12},{name:A13},{name:A14}],
{name:A2 {name:A22},{name:A23},{name:A24}]}
]
}];

我想使用这个而不是一个外部json文件,我该如何实现?

解决方案

解决方案



1.您可以将JSON数据分配给变量name



2.使用一个函数获取 JSON 数据



小提琴 1解决方案



小提琴 for 2解决方案

  var root = getData(),
nodes = cluster.nodes
link = cluster.links(nodes);


http://bl.ocks.org/mbostock/4339083 am using this

instead of d3.json("/d/4063550/flare.json", function(error, flare) {

how do i make it use the json file within the html, like say i have

var jsonData = [{
 "name": "A",
 "children": [  
  {"name": "A1", "children": [{"name": "A12"},{"name": "A13"},{"name": "A14"}]  },
  {"name": "A2",    "children": [{"name": "A22"},{"name": "A23"},{"name": "A24"}]  }
 ]
}];

and i want to use this instead of an external json file, how do i achieve this ?

解决方案

Solution:

1.you can assign the JSON data to variable name then You can build the tree layout

2.use one function to get the JSON data

Fiddle for 1 solution

Fiddle for 2 solution

    var root = getData(),
    nodes = cluster.nodes(root),
    links = cluster.links(nodes);

这篇关于在d3.js中嵌入json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆