从localhost获取json数据以在D3中使用 [英] getting json data from localhost to use in D3

查看:123
本文介绍了从localhost获取json数据以在D3中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个D3气泡图,使用json数据。我使用sinatra作为我的应用程序,我的json数据可在localhost:4567 / data.json

I'm creating a D3 bubble chart, using json data. I'm using sinatra for my app, and my json data is available at localhost:4567/data.json

我尝试使用

var myData = [];
$.get('data.json', function(data) {
  myData = data;
  console.log(myData);
.......

我在javascript控制台中获取正确的值,但是气泡图不呈现的代码工作,如果我复制和粘贴数据从'data.json'并将其设置为var,但如果我使用$ get方法,它不工作。)

and I get the correct values in the javascript console, but the bubble chart does not render. (The rest of the code works if I copy and paste the data from 'data.json' and set it to a var, but it does not work if I use the $get method).

您对我如何从本地主机访问此json数据有任何想法:4567?

Do you have any ideas on how I could access this json data from localhost:4567?

非常感谢,

Tim

推荐答案

你可以简单地使用
d3.json('data.json',function data){
myData = data;
console.log(myData);
.......

you can simply use d3.json('data.json', function(data) { myData = data; console.log(myData); .......

json文件

这篇关于从localhost获取json数据以在D3中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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