Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
_jespers_
Partner - Creator II
Partner - Creator II

Pivot table with visualization API

Is there any way that I can get the second dimension to be in the column section per default with the visualization API for the pivot-table component so it looks like this?

Skärmklipp.PNG

Because using the following code is only stacking the dimensions in the rows:

app.visualization.create(

                  'pivot-table',

                  [

                    {

                      "qDef": {

                        "qFieldDefs": [

                          "Dim1"

                        ],

                        "qFieldLabels": [

                          "Dim1"

                        ]

                      },

                      "qNullSuppression": true

                    },

                    {

                      "qDef": {

                        "qFieldDefs": [

                          "Dim2"

                        ],

                        "qFieldLabels": [

                          "Dim2"

                        ]

                      },

                      "qNullSuppression": true

                    },

                    {

                      "qDef": {

                        "qLabel": "Count(Dim3)",

                        "qDef": "Count(Dim3)",

                        "qNumFormat": {

                          "qType": "F",

                          "qnDec": 0,

                          "qUseThou": 0,

                          "qFmt": "# ##0",

                          "qDec": ".",

                          "qThou": ","

                        }

                      }

                    }

                  ],

                  {

                    "showTitles": true,

                    "title": "Pivot Table"

                  }

                ).then(function(vis){

                    vis.show("QV01");

                });

Skärmklipp2.PNG

1 Solution
3 Replies
_jespers_
Partner - Creator II
Partner - Creator II
Author

Hi Erik,

Yes, that worked! Thank you!

If anyone is interested in what changes I did it is in the options where I added the "qHyperCubeDef":

app.visualization.create(

                  'pivot-table',

                  [

                    {

                      "qDef": {

                        "qFieldDefs": [

                          "Dim1"

                        ],

                        "qFieldLabels": [

                          "Dim1"

                        ]

                      },

                      "qNullSuppression": true

                    },

                    {

                      "qDef": {

                        "qFieldDefs": [

                          "Dim2"

                        ],

                        "qFieldLabels": [

                          "Dim2"

                        ]

                      },

                      "qNullSuppression": true

                    },

                    {

                      "qDef": {

                        "qLabel": "Count(Dim3)",

                        "qDef": "Count(Dim3)",

                        "qNumFormat": {

                          "qType": "F",

                          "qnDec": 0,

                          "qUseThou": 0,

                          "qFmt": "# ##0",

                          "qDec": ".",

                          "qThou": ","

                        }

                      }

                    }

                  ],

                  {

                    "qHyperCubeDef":{

                         "qNoOfLeftDims": 1

                    },

                    "showTitles": true,

                    "title": "Pivot Table"

                  }

                ).then(function(vis){

                    vis.show("QV01");

                });

09999
Contributor II
Contributor II

HI Eric,

 

I am trying to build something as you did . Progmatically I want  to set what columns should be in pivot. For some reason I am not able to get it working. Any other things that I need to set for qNoOfLeftDims to work? below is the code. I see pivot table rendering but all dimensions are on left. Ideally in below example I want "year" to be at top i.e. column grouped by year. 

 

let pro = {
"qHyperCubeDef": {
"qDimensions": [{
"qDef": {
"qFieldDefs": ["Company"],
"qFieldLabels": ["Company"]
}
},
{
"qDef": {
"qFieldDefs": ["Company Name"],
"qFieldLabels": ["Company Name"]
}
},
{
"qDef": {
"qFieldDefs": ["Year"],
"qFieldLabels": ["Year"]
}
}],
"qMeasures": [{
"qDef": {
"qDef": "Sum([Quantity])",
"qLabel": "QUantity TOtal",
"qNumFormat": {
"qType": "F",
"qnDec": 0,
"qUseThou": 1,
"qFmt": "#,##0",
"qDec": ".",
"qThou": ","
}
}
}],
"qNoOfLeftDims": 2,
}
}
qlikApp.visualization.create('pivot-table', null, pro)
.then(function (reply) {
reply.show('vis' + favVisual.id);

});