# Change the dimension of a visualization on the fly

Change the dimension of a visualization on the fly by updating the property qActiveField using the [ApplyPatches method](https://help.qlik.com/en-US/sense-developer/November2024/Subsystems/EngineJSONAPI/Content/service-genericobject-applypatches.htm).

Information noteThe visualization should contain a cycling group (qGrouping is C in the definition of the visualization).

Information noteFor more information on the properties qGrouping and qActiveField, see [HyperCubeDef](https://help.qlik.com/en-US/sense-developer/November2024/Subsystems/EngineJSONAPI/Content/models-hypercubedef.htm) or [ListObjectDef](https://help.qlik.com/en-US/sense-developer/November2024/Subsystems/EngineJSONAPI/Content/models-listobjectdef.htm).

## Example

[](https://help.qlik.com/en-US/sense-developer/Subsystems/EngineAPI/Content/Sense_EngineAPI/WorkingWithAppsAndVisualizations/CreateVisualizations/change-dimension-visualization-on-fly.htm)

#### The goal is to change the dimension of a visualization on the fly.

1. Create a transient list object with three dimensions (qFieldDefs): Country, Region and City. The identifier of the object (qId) is ListObject01. The three dimensions are added into a cyclic group (qGrouping is C). The initial data fetch is composed of the first three rows (qHeight is 3) from the top left. The active field (qActiveField) is 0 (dimension Country).

The client sends:

```
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "CreateSessionObject",
  "handle": 1,
  "params": [
    {
      "qInfo": {
        "qId": "ListObject01",
        "qType": "ListObject"
      },
      "qListObjectDef": {
        "qStateName": "$",
        "qLibraryId": "",
        "qDef": {
          "qFieldDefs": [
            "Country",
            "Region",
            "City"
          ],
          "qFieldLabels": [
            "Country L",
            "Region L",
            "City L"
          ],
          "qSortCriterias": [
            {
              "qSortByLoadOrder": 1
            }
          ],
          "qGrouping": "C",
          "qActiveField": 0
        },
        "qInitialDataFetch": [
          {
            "qTop": 0,
            "qLeft": 0,
            "qHeight": 3,
            "qWidth": 1
          }
        ]
      }
    }
  ]
}
```

The engine returns:

```
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "qReturn": {
      "qType": "GenericObject",
      "qHandle": 2
    }
  },
  "change": [
    2
  ]
}
```

The list object is created and the handle of the object is 2.

2. Get the layout of the list object. The handle of the request is 2 because the list object uses 2 as a handle.

The client sends:

```
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "GetLayout",
  "handle": 2,
  "params": []
}
```

The engine returns:

```
{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "qLayout": {
      "qInfo": {
        "qId": "ListObject01",
        "qType": "ListObject"
      },
      "qSelectionInfo": {},
      "qListObject": {
        "qStateName": "$",
        "qSize": {
          "qcx": 1,
          "qcy": 22
        },
        "qDimensionInfo": {
          "qFallbackTitle": "Country L",
          "qApprMaxGlyphCount": 14,
          "qCardinal": 22,
          "qSortIndicator": "A",
          "qGroupFallbackTitles": [
            "Country L",
            "Region L",
            "City L"
          ],
          "qGroupPos": 0,
          "qStateCounts": {
            "qLocked": 0,
            "qSelected": 0,
            "qOption": 22,
            "qDeselected": 0,
            "qAlternative": 0,
            "qExcluded": 0,
            "qSelectedExcluded": 0,
            "qLockedExcluded": 0
          },
          "qTags": [
            "$ascii",
            "$text"
          ],
          "qDimensionType": "D",
          "qGrouping": "C",
          "qNumFormat": {
            "qType": "R",
            "qnDec": 14,
            "qUseThou": 1,
            "qFmt": "##############",
            "qDec": ".",
            "qThou": ","
          },
          "qIsAutoFormat": true,
          "qGroupFieldDefs": [
            "Country",
            "Region",
            "City"
          ]
        },
        "qExpressions": [],
        "qDataPages": [
          {
            "qMatrix": [
              [
                {
                  "qText": "United States",
                  "qNum": "NaN",
                  "qElemNumber": 0,
                  "qState": "O"
                }
              ],
              [
                {
                  "qText": "Denmark",
                  "qNum": "NaN",
                  "qElemNumber": 1,
                  "qState": "O"
                }
              ],
              [
                {
                  "qText": "Spain",
                  "qNum": "NaN",
                  "qElemNumber": 2,
                  "qState": "O"
                }
              ]
            ],
            "qTails": [],
            "qArea": {
              "qLeft": 0,
              "qTop": 0,
              "qWidth": 1,
              "qHeight": 3
            }
          }
        ]
      }
    }
  }
}
```

The active field is Country. Values United States, Denmark and Spain are displayed and are in optional state.

3. Change the active field to activate the field Region (qActiveField is 1).

The client sends:

```
{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "ApplyPatches",
  "handle": 2,
  "params": [
    [
      {
        "qPath": "/qListObjectDef/qDef/qActiveField",
        "qOp": "replace",
        "qValue": "1"
      }
    ],
    true
  ]
}
```

The engine returns:

{ "jsonrpc": "2.0", "id": 3, "result": {}, "change": [ 2 ] }

The active field is Region.

4. Get the layout of the list object. The handle of the request is 2 because the list object uses 2 as a handle.

The client sends:

{ "jsonrpc": "2.0", "id": 4, "method": "GetLayout", "handle": 2, "params": [] }

The engine returns:

{ "jsonrpc": "2.0", "id": 4, "result": { "qLayout": { "qInfo": { "qId": "ListObject01", "qType": "ListObject" }, "qHasSoftPatches": true, "qSelectionInfo": {}, "qListObject": { "qStateName": "$", "qSize": { "qcx": 1, "qcy": 240 }, "qDimensionInfo": { "qFallbackTitle": "Region L", "qApprMaxGlyphCount": 22, "qCardinal": 240, "qSortIndicator": "N", "qGroupFallbackTitles": [ "Country L", "Region L", "City L" ], "qGroupPos": 1, "qStateCounts": { "qLocked": 0, "qSelected": 0, "qOption": 240, "qDeselected": 0, "qAlternative": 0, "qExcluded": 0, "qSelectedExcluded": 0, "qLockedExcluded": 0 }, "qTags": [ "$text" ], "qDimensionType": "D", "qGrouping": "C", "qNumFormat": { "qType": "R", "qnDec": 14, "qUseThou": 1, "qFmt": "##############", "qDec": ".", "qThou": "," }, "qIsAutoFormat": true, "qGroupFieldDefs": [ "Country", "Region", "City" ] }, "qExpressions": [], "qDataPages": [ { "qMatrix": [ [ { "qText": "Florida", "qNum": "NaN", "qElemNumber": 4, "qState": "O" } ], [ { "qText": "California", "qNum": "NaN", "qElemNumber": 2, "qState": "O" } ], [ { "qText": "Michigan", "qNum": "NaN", "qElemNumber": 11, "qState": "O" } ] ], "qTails": [], "qArea": { "qLeft": 0, "qTop": 0, "qWidth": 1, "qHeight": 3 } } ] } } } }

The active field is Region. Values Florida, California and Michigan are displayed and are in the optional state.