使用d3.json导入本地json文件不起作用 [英] Importing local json file using d3.json does not work

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

问题描述

我尝试使用 d3.json()导入本地.json文件。

I try to import a local .json-file using d3.json().

filename.json 与我的html文件存储在同一个文件夹中。

The file filename.json is stored in the same folder as my html file.

null。

d3.json("filename.json", function(json) {
    root = json;
    root.x0 = h / 2;
    root.y0 = 0;});
    . . . 
}

我的代码基本上与这个 d3.js示例

My code is basically the same as in this d3.js example

推荐答案

如果您在浏览器中运行,您无法加载本地文件

If you're running in a browser, you cannot load local files.

不过,您可以使用 jQuery的get 加载json或简单地在代码中硬编码如下:

You can, however load the json with jQuery's get or simply hardcode it within your code like this:

var json = {"my": "json"};
d3.json(json, function(json) {
    root = json;
    root.x0 = h / 2;
    root.y0 = 0;
});

这篇关于使用d3.json导入本地json文件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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