Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Trying to include second expression in Waterfall extension.

Hi all

In Waterfall extension i'm trying to include 2 expressions instead of 1 expression(default in extension code). In below code in bolded area of alert : d[1].qNum gives me all values of first expression, but d[2].qNum doesn't works for me and causing error.

Can anyone suggest me how i can achieve in getting the second expression values in the alert ?

var data = layout.qHyperCube.qDataPages[0].qMatrix

                .filter(function (d) {

                    return d[0].qText !== undefined;

                })

                .map(function (d, i, arr) {

                    return {

                        label: d[0].qText,

                        value: d[1].qNum,

                        element: d[0].qElemNumber,

                      alert : alert(d[1].qNum),

                      alert : alert(d[2].qNum),

                        sum: (i === 0) ? d[1].qNum : arr.map(function (d) {

                            return d[1].qNum;

                        }).reduce(function (prev, curr, idx, array) {

                            if (idx > i) return prev

                            else if ((idx==3 && i==3) || (idx==5 && i==5)) return curr

                            else if (idx==4 && i==4) return  array[5]; 

                            return prev + curr

                        })

                    }

                });

Thank in advance.

Regards,

Satish A.

8 Replies
sinanozdemir
Specialist III
Specialist III

Hi Satish,

It seems like you are not assigning d[2].qNum to a variable.

Create another variable:

value2: d[2].qNum

Hope this helps.

Alexander_Thor
Employee
Employee

First you need to change the max measures to 2 in the properties definition and add another measure to the extension in the client.

It's probably easier for you to just console log the layout object when the paint function fires to see the values inside it instead of doing it the way you are doing now so you see how the layout looks like un-tainted.

You can read this article in the Help Documentation around debugging your code, https://help.qlik.com/sense/2.0/en-us/developer/Subsystems/Extensions/Content/extensions-debugging-a...

This article explains how you can work with extension properties https://help.qlik.com/sense/2.0/en-us/developer/Subsystems/Extensions/Content/extensions-build-prope...

Not applicable
Author

Hi , thank you both. Unfortunately i missed this conversation for long time.

Alex,

i change the max measures to 2, and in the chart i'm able to insert an expression, but that expression doesn't gets affected in chart.

Do i needs to modify/include additional code in the javascript file, for effecting the chart with second expression ?

what exactly i was trying for is the second expression should calculate dynamically in reduce functionality javascript code.i.e(same as in qlikview the offset functionality in bar chart). The below code is generated static in javascript, instead of that what ever i had given in the second expression that should go in the reduce functionality.

var data = layout.qHyperCube.qDataPages[0].qMatrix

                .filter(function (d) {

                    return d[0].qText !== undefined;

                })

                .map(function (d, i, arr) {

                    return {

                        label: d[0].qText,

                        value: d[1].qNum,

                        element: d[0].qElemNumber,

                        sum: (i === 0) ? d[1].qNum : arr.map(function (d) {

                            return d[1].qNum;

                        }).reduce(function (prev, curr, idx, array) {

                            if (idx > i) return prev

                            else if ((idx==3 && i==3) || (idx==5 && i==5)) return curr

                            else if (idx==4 && i==4) return  array[5];

                            return prev + curr

                        })

                    }

                });

Please can you share your thoughts on achieving this.

Thanks in advance.

Regards,

Satish A.

Alexander_Thor
Employee
Employee

You probably just want to remove the reduce part completely since you want the second measure to be your offset and not the cumulative sum of previous bars.

You would feed your second measure into the y scale and then calculate the height of your bar as the y scale value of the first measure minus the y scale value of the second measure (the offset).

Not applicable
Author

Hi Alex, i'm new to this extensions. I included the second measure in chart, but the second measure is not evaluating. I think it needs to add some more code lines in the waterfall javascript file. And i'm not getting to figure where i needs to modify/append the new code in existing code of javascript file.

Can you provide some suggestions  how and where i needs modification in code ? Please find attached extension zip file and qvf

Thank you in advance.

Regards,

Satish A.

Alexander_Thor
Employee
Employee

I would recommend you read up on the some of the D3 tutorials.

Let’s Make a Bar Chart is a good one to get started to understand how data is bound to the DOM and how you can manipulate attributes in the enter selections.

A more comprehensive list of tutorials for D3 can be found here Tutorials · mbostock/d3 Wiki · GitHub

Not applicable
Author

Hey Satish,


Did you find the solution regarding the second Measure ? I have the same issue like you.


Could you please provide me your solution if you have one of course.


Thank you.


Regards,

MFE

dionverbeke
Luminary Alumni
Luminary Alumni

You have to remove the extension from your sheet and try again.

Somehow the dimension definitions get cached and are inconsistent.

Adding it again makes it consistent again.

kr,

Dion