Generic object in visualization extensions
The generic object is underlying all visualizations in Qlik Sense. This allows you to use the Qlik associative engine functionality. A generic object is created when your custom visualization extension is added to an app. It contains the initial properties specified and it is persisted in the app.
Properties and layout
The generic object has properties in a structure that you define. There are two kinds of properties:
- User defined: Qlik Sense only persist the properties and include them in the layout as-is. Their usage is then defined in the code.
- Qlik associative engine defined: The Qlik associative engine validate the properties and replaces them in the output - the layout - by the calculated counter parts. A qHyperCubeDef containing the dimension and measure definitions is replaced by a qHyperCube containing the calculated values.
Qlik Engine JSON API: qHyperCubeDef
Qlik Engine JSON API: qHyperCube
The properties of a visualization extension are set up in initialProperties.
Example: People chart initialProperties
initialProperties : {
version: 1.0,
qHyperCubeDef : {
qDimensions : [],
qMeasures : [],
qInitialDataFetch : [{
qWidth : 2,
qHeight : 50
}]
}
}
This creates a hypercube at root level so you know where to find your data when you define the paint method. The example above also creates a user defined property called version. The Qlik associative engine only persists user defined properties so you can easily check version history by using layout.version.
You can create visualization extensions with multiple hypercubes or visualization extensions without properties, hence without any hypercube at all. The Hello world visualization extension is an example of a visualization extension with no hypercube.
You can also create visualization extensions with other predefined properties:
- qListObject
- qStringExpression
- qValueExpression
Using qListObject
qListObject is underlying list boxes and is suitable if you want to create a list of all values from a field. The Horizontal listbox visualization extension exemplifies the qListObject together with some user defined properties.
A list object is a visualization that contains one dimension. When getting the layout of a list object (qListObjectDef), all values are rendered. If selections are applied to a list object, the selected values are displayed along with the excluded and the optional values.
Just like you can have multiple hypercubes in your properties, you can also have multiple list objects. If you have multiple list objects, you need to place them at different paths in your property structure.
Example: Horizontal listbox initialProperties
initialProperties : {
version : 1.0,
qListObjectDef : {
qShowAlternatives : true,
qFrequencyMode : "V",
qSortCriterias : {
qSortByState : 1
},
qInitialDataFetch : [{
qWidth : 2,
qHeight : 50
}]
},
fixed: true,
width: 25,
percent: true,
selectionMode: "CONFIRM"
}
Qlik Engine JSON API: qListObjectDef
Using multiple hypercubes
When creating visualization extensions with multiple hypercubes to combine several data sets, you need to place the hypercubes at different paths in your property structure.
Example: Multiple hypercubes defined in initialProperties
initialProperties : {
qHyperCubeDef : {
qDimensions : [],
qMeasures : [],
qInitialDataFetch : [{
qWidth : 10,
qHeight : 50
}]
},
second:{
qHyperCubeDef : {
qDimensions : [],
qMeasures : [], ,
qInitialDataFetch : [{
qWidth : 10,
qHeight : 50
}]
}
}
}
Using qStringExpression and qValueExpression
You can use qStringExpression or qValueExpression if you want an expression to be evaluated. A string expression is an expression that returns a single string value. An expression value is an expression that returns a single numeric value.
Example: qStringExpression and qValueExpression
version : {
qStringExpression : "=QlikViewVersion ()"
},
fields : {
qValueExpression : "=Count(DISTINCT $Field)"
}
Qlik Engine JSON API: qStringExpression
Qlik Engine JSON API: qValueExpression