javascript - 无法在 d3 js 中加载 json 数据
问题描述
我是 D3 JS 的新手。我想从 D3 js 加载 json 数据。在这里,我不确定是否加载了 json。在这里,没有出现消息。我想显示 html 和 json 数据,
我的数据.json
[
{"name":"Hira","age":35},
{"name":"Basu","age":26},
{"name":"Mukhia","age":30}
]
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
<script src="https://d3js.org/d3.v5.min.js"></script>
</head>
<body>
<script>
d3.json("./mydata.json", function(data) {
console.log(data);
});
</script>
</body>
</html>
希望大家能给点提示。
解决方案
在这里,我有一个解决方案。
d3.json("./mydata.json").then(function(data){
console.log(data);
});
在新版本中,我们必须指定 then 函数。在 then 函数中,我们必须创建回调函数。
推荐阅读
- wordpress - Fusion Builder 中继器
- reactjs - 如何在 Fluent UI React 中使用网格布局
- java - Spring Boot - 必需的 @RequestBody 类字段
- c# - 使用c#去除带问号的黑色菱形
- c# - 使用 WebClient.UploadFile 将文件上传到 WebDAV 服务器返回 401
- c# - c# - 字段名称中的下划线
- python - 跳过没有属性的元组 Python NLTK
- flutter - google_sign_in signinSilently gets APIException PlatformException(sign_in_required, com.google.android.gms.common.api.ApiException: 4: 4: , null)
- matlab - 在 uiputfile 中设置文件夹 - Matlab
- java - 如何在java中分隔特定标签