To increase the flexibility of a single chart object, you can set it up so that the dimension used is based on what the user wants to see. This is a much more efficient use of space for single sheets and makes the whole experience much more dynamic.
For the purpose of this recipe, we will make use of the sales information for different fruits as defined in the script:
QS_DynamicCharts
.Transactions: Load Mod(IterNo(),26)+1 AS Period, Pick(Ceil(3*Rand()),'Standard','Premium','Discount') AS ProductType, Pick(Ceil(6*Rand()),'Apple','Orange','Cherry','Plum','Fig', 'Pear') AS Category, Pick(Ceil(3*Rand()),'Heavy','Medium','Light') AS Weight, Pick(Ceil(2*Rand()),'2013','2014') AS Year, Round(1000*Rand()*Rand()*Rand()) AS Sales Autogenerate 20 While Rand()<=0.5 or IterNo()=1; SET vDimension = 'GetFieldSelections(Dimensions)'; Dimensions: LOAD * INLINE [ Dimensions Weight ProductType Category Period ];
Sum(Sales)
= [' & Pick(Match($(vDimension),'Weight','ProductType', 'Category'),Weight,ProductType,Category) & ']'
In the script loaded at the beginning of the recipe, we set a variable called vDimension
. The GetFieldSelections()
function will return the values selected in the field we specify inside the brackets GetFieldSelections (Dimensions)
. The Dimensions
field is simply a hardcoded list of specific fields in the Data model. The code we wrote in the dimension field of the chart uses this variable value to set the dimension dynamically to whatever value the user picks in the list box we created.
If you are running Qlik Sense 2.1.1, then you can now enter expressions in the chart title area. If so, enter the following code:
='Showing Sales by: ' & $(vDimension)
This displays the selected dimension in the chart title dynamically. If you are running an earlier version of Qlik Sense, simply leave the label blank. After this, I would suggest creating a textbox explaining the chart, which will display whatever the value is, in the associated list box. You can also use the preceding expression in the explanation textbox.