Qlik Community

Qlik Sense Integration, Extensions, & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

Announcements
See why Qlik is recognized as a Leader for the 10th year in a row – and discover how Qlik can help put your business in the lead. Get Report
Highlighted
Partner
Partner

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

Accepted Solutions
Highlighted
ErikWetterberg
Honored Contributor

Re: Pivot table with visualization API

3 Replies
Highlighted
ErikWetterberg
Honored Contributor

Re: Pivot table with visualization API

Highlighted
Partner
Partner

Re: Pivot table with visualization API

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");

                });

Highlighted
09999
New Contributor II

Re: Pivot table with visualization API

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);

});