Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
45
How to transform json graph data into 2d array having parent and child attributes?
posted

I using [igDoughnutChart][1] for my web-page, I want a graph which shows the following hierarchy
 
 - source of attack (inside)
     - login abuse
     - dos
     - spyware
     - worm
 - outside attackers
     - spying
     - social attacks
        

The current object array looks like (also [demo][2])

    var data = [
                  { "attacksource": 43, "attacktype": 60, "AT":"DoS","Label": "iNISDE" },
                  { "attacksource": 29, "attacktype": 40, "AT":"login abuse","Label": "outside" }
    ];


**I want to change this to do following:-** (also shown above)

Where I have a parent and child values in 2d array so above code is to transform as

 
      var data =
            [
                [{"attacksource": 43,"Label":"Inside"}],
                [
                     {"attacktype": 13,"Label":"dos"},
                     {"attacktype": 13,"Label":"virus"}...
                ]
            ];


I'm not sure If I have initialized / assigned 2d using **objects**  correctly.I appreciate If someone can look at the code, and let me know if I'm doing this right.

**UPDATE**

The jsbin example is just something to illustrate my requirements for the new code. For e.g <code>"Label":"virus"</code> is currently hardcoded, in real code (which I cannot do on jsbin) is I will get the values from DB.








**[VISUAL EXAMPLE][3]**



  [1]: http://help.infragistics.com/jQuery/2013.1/ui.igdoughnutchart
  [2]: http://jsbin.com/oXuMAzU/4/edit
  [3]: http://lh6.ggpht.com/-WsYb0mzuKs0/Umm4pmcykTI/AAAAAAAARoQ/I4NLhJ2whng/s1600-h/image9.png

//