I've been trying to convert JSON like this into something that d3 can work with but I have been having a bit of trouble. Here's the example JSON
[{
"name" : "MATH210",
"work" : {
"assessment1" : {
"mark" : 65,
"weight" : 40
},
"assessment2" : {
"mark" : 65,
"weight" : 60
}
},
"overallMark" : 95
},
{
"name" : "MATH215",
"work" : {
"assessment1" : {
"mark" : 67,
"weight" : 30
},
"assessment2" : {
"mark" : 65,
"weight" : 45
},
"exam" : {
"mark" : 72,
"weight" : 25
}
},
"overallMark" : 85
},
{
"name" : "MATH220",
"work" : {
"assessment1" : {
"mark" : 65,
"weight" : 50
},
"assessment2" : {
"mark" : 65,
"weight" : 50
}
},
"overallMark" : 75
}]
I'm quite new to d3 but all the examples I've read and worked through have had data in the form of arrays so that's what my first approach focused on.
I'll post a little bit of code so you can better understand what I've done. So I first create an array containing module objects from the JSON using code like this
var count = 0;
// loop through json and instantiate each
// module and store in the modules array
$.each(json, function(i, item) {
progress.modules[count] = new Module( i , item );
count++;
});
Then I use lots of nested for/in loops to extract the data I want and store them in lots of arrays for each module, each module has 3 different arrays.
// Arrays that will hold all the broken down data
this.workNames = [], this.marks = [], this.weights = [];
This approach works but won't be appropriate for a lot of data.
All I want to do is draw some pie graphs based on overall marks and their weights and a scatter graph. From what I have read elsewhere on stack overflow and across the web I have a feeling that there is a much more graceful way to take this data and transform it into something that d3 can work with.
Maybe by using d3.nest() like this
Does anybody have any ideas how I can transform this JSON to work well with d3 without using the approach above?
Thanks in advance :)