Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello, I am trying to figure out the purpose of qAttributeDimensions and qAttributeExpressions when defining the properties of a Hypercube in the Visualization API (https://help.qlik.com/en-US/sense-developer/April2018/Subsystems/EngineAPI/Content/GenericObject/Pro...). The documentation isn't very clear on this topic.
My current understanding is that it can be used to define the properties of the dimension/expression much like how you could define "Background Color" or "Text Color" in QlikView. I'm just not sure on the syntax for this though.
My end goal is to have a bar chart with multiple measures, and be able to assign a different color to each measure.
I know this is an old question but I thought I'd add a possible solution.
To add an expression to your Measure within the properties panel, you need to create the following definition obj. Note the "items" property within the measure's definition.
return { type: "items", component: "accordion", items: { dimensions: { uses: "dimensions", min: 1, max: 1 }, measures: { uses: "measures", min: 1, max: 1, items: { colorBackExpression: { type: "string", label: "Background color expression", ref: "qAttributeExpressions.0.qExpression", component: "expression", }, colorTextExpression: { type: "string", label: "Text color expression", ref: "qAttributeExpressions.1.qExpression", component: "expression", } }, sorting: { uses: "sorting" }, settings: { uses: "settings" } } }
Then within your paint() function, you will find this result of the expression within the following property qAttrExps.qValues[0].qText of the Measure within the result set returned.
The full path would be something as follows. layout.qHyperCube.qDataPages.qMatrix[0][0].qAttrExps.qValues[0].qText but in most cases, you'd be looping through the dataset so you probably won't require the full path.
You can also find the definition of the expression on the measure within the qMeasureInfo property on the HyperCube.
layout.qHyperCube.qMeasureInfo[0].qAttrExprInfo[0]
Hope that helps.
Hi Organgrindingmo,
I'm new to building extension, if I have dispayed the expression text box in accordion, how should I write the paint function to make it change my measure text color?
Please help!!!
Thanks in advance. 🙂
Hi
While looping through the qMatrix, you'll need to check if the cell has the qAttrExps set. If it does, then set the style of the element or the parent of the element that you are targeting.
Below is the code I use within the render function to check if there is a value supplied for the color and then apply it as a style attribute to the containing td element.
for (var row = 0; row < qMatrix.length; row++) { // Get current row data var currentRow = qMatrix[row]; // Iterate through each column of the row for (var col = 0; col < currentRow.length; col++) { // Get current cell data var currentCell = currentRow[col]; // Check for attribute expressions (Set background and forground colour) if (currentCell.qAttrExps) { if (currentCell.qAttrExps.qValues[0].qText) { td.style.backgroundColor = currentCell.qAttrExps.qValues[0].qText; } if (currentCell.qAttrExps.qValues.length === 2 && currentCell.qAttrExps.qValues[1].qText) { td.style.color = currentCell.qAttrExps.qValues[1].qText; } } } }
Hope this helps