I had a graph working with CSV but we've decided to get it up and running with JSON instead. I'm having a difficult time parsing the nested pieces so that I can use them.
我有一个使用CSV的图形,但是我们决定用JSON来运行它。我很难解析嵌套的部分,以便使用它们。
Here is the fiddle link and the code block (fiddle is not working) - I'm not looking for someone to get the whole thing working... I just need help with the parsing and example of using the data.
这是古提琴链接和代码块(古提琴不工作)——我不是在找一个人来让整个东西工作……我只需要帮助解析和使用数据的示例。
http://jsfiddle.net/Mmdc8/
d3.json("https://dl.dropboxusercontent.com/u/23726217/progtime.json", function (error, jsondata) {
var studyData = d3.entries(jsondata);
console.log(JSON.stringify(studyData[0]));
studyData.forEach(function (d) {
d.value.name = d.value.name
});
console.log(studyData.value.name);
1 个解决方案
#1
1
Your JSON file has the following structure:
您的JSON文件具有以下结构:
- details: [...]
- annotations: [...]
- dates: [...]
Each one of this fields, contains an array with objects. To access the data, you don't need to use entries:
每个字段都包含一个带有对象的数组。要访问数据,您不需要使用条目:
d3.json(jsonUrl, function(error, jsondata) {
// Handle errors getting or parsing the data
if (error) { return error; }
// Parse the dates
var startDate = new Date(jsondata.dates.StartDate),
endDate = new Date(jsondata.dates.EndDate);
// It will print the array of objects
console.log(jsondata.details);
// Print the start and end dates
console.log([startDate, endDate]);
});
EDIT: Added access to the dates.
编辑:添加对日期的访问。
#1
1
Your JSON file has the following structure:
您的JSON文件具有以下结构:
- details: [...]
- annotations: [...]
- dates: [...]
Each one of this fields, contains an array with objects. To access the data, you don't need to use entries:
每个字段都包含一个带有对象的数组。要访问数据,您不需要使用条目:
d3.json(jsonUrl, function(error, jsondata) {
// Handle errors getting or parsing the data
if (error) { return error; }
// Parse the dates
var startDate = new Date(jsondata.dates.StartDate),
endDate = new Date(jsondata.dates.EndDate);
// It will print the array of objects
console.log(jsondata.details);
// Print the start and end dates
console.log([startDate, endDate]);
});
EDIT: Added access to the dates.
编辑:添加对日期的访问。