2

I am trying to understand if there is any way to use other json format for chart in nvd3 or d3.

Like if I give,

var modulechart_data = [
      {
        key : "Passed",
        values :[
          { x : "Module A", y : 2},
          { x : "Module B", y : 12},
          { x : "Module C", y : 14},
          { x : "Module D", y : 2}
        ]
      },
      {
        key : "Failed",
        values :[
          { x : "Module A", y : 6},
          { x : "Module B", y : 3},
          { x : "Module C", y : 4},
          { x : "Module D", y : 2}
        ]
      }
   ];

it will work without any problem.

Now my real json data is coming like this,

var module_data = {
  "ModuleExecutionStatus": [
    {
      "ModuleName": "Module A",
      "ExecutionData": {
        "Passed": 1,
        "Failed": 3
      }
    },
    {
      "ModuleName": "Module B",
      "ExecutionData": {
        "Passed": 3,
        "Failed": 1
      }
    }
  ]
}

I am creating multiBarHorizontalChart of nvd3. But with real json data, i am not able to deploy it.

I am trying to figure out, do I have to change whole original json data to default json format ? or how can I map this json data for chart ?

Nitz
  • 1,690
  • 11
  • 36
  • 56

1 Answers1

2

Here's a link that you might find helpful for referring to your original data and setting up the x and y to comply with NVD3's structure. You would also have to specify the key, which is not covered in that answer. Otherwise, Lars is probably right in where you have to reformat all of your original data.

Community
  • 1
  • 1
aonthemoon
  • 50
  • 1
  • 11