4 Replies Latest reply: Nov 10, 2014 6:49 PM by Anirudh Asher RSS

    D3.js and JSON input

    Pablo Labbe

      Hi All,


         Anyone dealed with d3.js and json input ?  I'm doing some research using d3.js to build a tree node view. I've found a sample, here,D3.js Drag and Drop, Zoomable, Panning, Collapsible Tree with auto-sizing. but reviewing the code it read the data from a json format dataset.


        I'm newbie in javascript  programing and json, then I suppose I need to create a function to read QV.Data.Rows and converts it to json format. Any clue on how to do it ?

      Best Regards,

      Pablo Labbe

        • Re: D3.js and JSON input
          Nicole Smith
          //Declaring a two-dimensional array (an array of arrays)
          var input = new Array(this.Data.Rows.length);
          //Getting the data from QlikView
          for (var j = 0; j < this.Data.Rows.length; j++) {
               input[j] = this.Data.Rows[j][0].text;
          //Changing the array into a hierarchical json
          var output = [];
          for (var i = 0; i < input.length; i++) {
               var chain = input[i].split("/");
               var currentNode = output;
               for (var j = 0; j < chain.length; j++) {
                    var wantedNode = chain[j];
                    var lastNode = currentNode;
                    for (var k = 0; k < currentNode.length; k++) {
                         if (currentNode[k].name == wantedNode) {
                         currentNode = currentNode[k].children;
               // If we couldn't find an item in this list of children
               // that has the right name, create one:
                    if (lastNode == currentNode) {
                         var temp = wantedNode.split('} ');
                         var newNode = currentNode[k] = { id: wantedNode, name: temp[1], children: [] };
                         currentNode = newNode.children;
          var json = output;
          • Re: D3.js and JSON input

            Hello Pablo,

            I was also looking for a way to bring this chart into Qlikview and I came across your post
            D3.js Drag and Drop, Zoomable, Panning, Collapsible Tree with auto-sizing.


            Have you had any success in bringing this chart into Qlikview using the above code as yet? If so, then how did you achieve it? Any help would be greatly appreciated. Thanks