Let's Get Social!
Focal Point    Focal Point Forums    WebFOCUS/FOCUS Forum on Focal Point     [CLOSED] Simple percentage calculation
 Go New Search Notify Tools Reply
 [CLOSED] Simple percentage calculation
Silver Member
 posted August 10, 2020 06:10 AM
Hello, The code is very simple. I get individual segment percentage correctly but when i try to print percentage of a single segment on a graph thats when % reverts back to 100.00%. I am sure i am missing a basic thing. Can someone please help on this.
TABLE FILE CAR
SUM PCT.CNT.CAR/D20.2% AS 'PERCENT'
BY COUNTRY
ON TABLE NOTOTAL
END
----This code gives individual value percentage against total % correctly. But when a value is dynamically inputted from the user and while printing its % it gives 100%. Kindly advise.

This message has been edited. Last edited by: FP Mod Chuck,

 Posts: 31 | Registered: July 17, 2020 IP
Virtuoso
 posted August 10, 2020 08:21 AM Hide Post
If I do understand properly your issue : "But when a value is dynamically inputted from the user and while printing its % it gives 100%" you mean that when you filter the COUNTRY based on an input selection it gives you 100%

Yes it does, because the filtered COUNTRY is 100% of the whole selected value.
Below is giving you the proper result

```-DEFAULTH &CNTRY = 'ITALY'
TABLE FILE CAR
SUM PCT.CNT.CAR/D20.2% AS 'PERCENT'
BY COUNTRY
ON TABLE HOLD AS EXTDATA
END
-RUN

TABLE FILE EXTDATA
PRINT PERCENT
BY COUNTRY
WHERE COUNTRY EQ '&CNTRY';
ON TABLE NOTOTAL
END
-RUN
```

WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007

 Posts: 2392 | Location: Montreal Area, Qc, CA | Registered: September 25, 2013 IP
Silver Member
 posted August 10, 2020 09:40 AM Hide Post
Thank you MartinY. Apologies for insufficient information. So below is the data.
COUNTRY %
FRANCE 20.00%
MALDIVES 30.00%
ITALY 15.00%
USA 25.00%
UK 10.00%

When the report is run, user should be given an option to select a value from the dropdown and if user selects ITALY then the pie chart should show ring with 15% occupied in a colour and remaining left blank and in the middle hole the % which is 15% should be displayed. If user selects multiple value like FRANCE and MALDIVES then output ring should be 20% of the ring in a colour representing FRANCE, 30% pf the ring in a colour representing MALDIVES and the centre hold should display sum of these 2 total which is 50%.

So basically, at any of time the ring should be 100% and based on data selected only its percentage to be occupied and remaining space in the ring to be left unoccupied.

This message has been edited. Last edited by: WF Learner,

 Posts: 31 | Registered: July 17, 2020 IP
Virtuoso
 posted August 10, 2020 03:54 PM Hide Post
I can think of possible programming solution to this (nothing out of the box and probably not possible using IA) but cannot figure how the pie center (totalLabel propertie) can display a different value than the pie total which will be 100%

WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007

 Posts: 2392 | Location: Montreal Area, Qc, CA | Registered: September 25, 2013 IP
Silver Member
 posted August 12, 2020 04:47 AM Hide Post
Hi MartinY. Below code works fine for one value selection by the user. But when user multi-selects that is when the issue is. Though multi value is selected, WF picks one value either first or last and displays only its value in the centre label also the ring total % is not 100% instead its showing selection values % as ring total % but ring total % should be 100% and occupied should be % sum of values selected.
SET ASNAMES=ON
SET HOLDLIST=PRINTONLY
SET HOLDFORMAT=ALPHA
TABLE FILE CAR
SUM
PCT.CNT.CAR AS 'PERCENTAGE'
BY COUNTRY
ON TABLE HOLD AS A1
END
GRAPH FILE A1
SUM
PERCENTAGE/D8.2% AS 'PERCENTAGE'
BY COUNTRY
WHERE COUNTRY EQ &COUNTRY.(OR(FIND CAR.COUNTRY IN CAR |FORMAT=A23V,SORT=ASCENDING)).COUNTRY:.;

This message has been edited. Last edited by: WF Learner,

 Posts: 31 | Registered: July 17, 2020 IP
Virtuoso
 posted August 12, 2020 07:55 AM Hide Post
Always use the code tag when posting code sample or result sample.
It's the last icon from the ribbon that looks like the below
`</>`

Below may be one option where pie center display the value total and the tooltip value and pourcentage

```DEFINE FILE CAR
DUMMY /A1 = 'X';
END
TABLE FILE CAR
SUM CNT.CAR AS 'TOTCAR'
BY DUMMY

SUM CNT.CAR AS 'NBCAR'
BY DUMMY
BY COUNTRY
ON TABLE HOLD AS A1
END
-RUN

ENGINE INT CACHE SET ON
SET HTMLENCODE=ON
SET ARGRAPHENGINE=JSCHART
SET GRAPHDEFAULT=OFF
-DEFAULTH &WF_STYLE_UNITS='PIXELS';
-DEFAULTH &WF_STYLE_HEIGHT='240.0';
-DEFAULTH &WF_STYLE_WIDTH='460.0';
-DEFAULTH &WF_TITLE = 'WebFOCUS';

GRAPH FILE A1
SUM COMPUTE PCT/D8.2% = IF TOTCAR NE 0 THEN NBCAR / TOTCAR * 100 ELSE 0; AS 'PERCENTAGE'
BY COUNTRY

WHERE COUNTRY EQ &COUNTRY.(OR(FIND CAR.COUNTRY IN CAR |FORMAT=A23V,SORT=ASCENDING)).COUNTRY:.;

ON GRAPH PCHOLD FORMAT JSCHART
ON GRAPH SET VZERO OFF
ON GRAPH SET GRWIDTH 1
ON GRAPH SET UNITS &WF_STYLE_UNITS
ON GRAPH SET HAXIS &WF_STYLE_WIDTH
ON GRAPH SET VAXIS &WF_STYLE_HEIGHT
ON GRAPH SET LOOKGRAPH PIE
ON GRAPH SET AUTOFIT ON
ON GRAPH SET STYLE *
*GRAPH_SCRIPT
setPieDepth(0);
setPieTilt(0);
setCurveFitEquationDisplay(false);
setPlace(true);
*END
INCLUDE=IBFS:/FILE/IBI_HTML_DIR/ibi_themes/Warm.sty,\$
TYPE=REPORT, TITLETEXT=&WF_TITLE.QUOTEDSTRING, \$
TYPE=HEADING, LINE=1, ITEM=1, OBJECT=TEXT, FONT='TIMES NEW ROMAN', SIZE=9, COLOR=RGB(8 97 74), STYLE=NORMAL, \$
TYPE=HEADING, LINE=2, ITEM=1, OBJECT=TEXT, FONT='TIMES NEW ROMAN', SIZE=8, COLOR=RGB(8 97 74), STYLE=NORMAL, \$
TYPE=DATA, COLUMN=N1, BUCKET=color, \$
TYPE=DATA, COLUMN=N2, BUCKET=measure, \$
*GRAPH_SCRIPT
setReportParsingErrors(false);
setSelectionEnableMove(false);
setDisplay(getLegendArea(),false);
*GRAPH_JS_FINAL
"pieProperties": {
holeSize: "40%",
totalLabel: {visible: true, font: 'Bold 12pt Sans-Serif', color: 'rgb(8,97,74)', numberFormat: '{{auto}}'}
},
"agnosticSettings": {
"chartTypeFullName": "Pie_Multi"
}
*END
ENDSTYLE
END
-RUN
```

WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007

 Posts: 2392 | Location: Montreal Area, Qc, CA | Registered: September 25, 2013 IP
Silver Member
 posted August 13, 2020 06:49 AM Hide Post
Thank you MartinY. But I am getting error while executing the code. FIELDNAME or COMPUTATIONAL ELEMENT NOT RECOGNIZED : TOTCAR NBCAR

 Posts: 31 | Registered: July 17, 2020 IP
Virtuoso
 posted August 13, 2020 07:38 AM Hide Post
You may miss the SET ASNAMES = ON at top of code
On my side I don't have to add it because it is part of a common profile.

WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007

 Posts: 2392 | Location: Montreal Area, Qc, CA | Registered: September 25, 2013 IP
Silver Member
 posted August 13, 2020 07:54 AM Hide Post
Thank you MartinY. I could see correct label getting displayed but the only issue is the ring should be of 100% and lets say the user is selecting Italy and Germany then total label is 40 with which % to be displayed and only 40% to be occupied in the ring rest 60% should be left out in say silver color. So ring should visualize like this, 20% for Italy in a color, 20% for Germany in another color so total 40% is occupied in the ring. Remaining in one color but the centre label should always be the selected value/s % total. Tooltip should be showing individual segment % when hovered over with also 100% mentioned in braces telling user that out of 100%, 20% is occupied by Italy. 20% is occupied by Germany.

 Posts: 31 | Registered: July 17, 2020 IP
Virtuoso
 posted August 13, 2020 09:01 AM Hide Post
As previously stated, the pie totalLabel properties (pie center value) will always be the measure total.
So, if England = 30%, France = 10% and W Germany = 20% and only those have been selected, then totalLabel is going to be 60% and the pie will be 100% of its size where England will be 50% of the whole pie, France 16.67% of the whole pie and W Germany 33.33% of the whole pie. This is how pie chart is working.

As for pie segment display as you request, possibly with programming it's going to be possible to do it but you will have constrains such as to insure that data (COUNTRY) is always in the same order and assign series color depending on number of selected countries. Also have to manage all possible series.
Where it's going to be more difficult is that you are using auto-prompt so, it's going to be more difficult to manage the number of selected countries.

Below is not working as expected because since you apply a filter then not all series exist.
But it's just to give you an idea
```SET ASNAMES = ON
DEFINE FILE CAR
DUMMY /A1 = 'X';
END
TABLE FILE CAR
SUM CNT.CAR AS 'TOTCAR'
BY DUMMY

SUM CNT.CAR AS 'NBCAR'
BY DUMMY
BY COUNTRY
ON TABLE HOLD AS A1
END
-RUN

ENGINE INT CACHE SET ON
SET HTMLENCODE=ON
SET ARGRAPHENGINE=JSCHART
SET GRAPHDEFAULT=OFF
-DEFAULTH &WF_STYLE_UNITS='PIXELS';
-DEFAULTH &WF_STYLE_HEIGHT='240.0';
-DEFAULTH &WF_STYLE_WIDTH='460.0';
-DEFAULTH &WF_TITLE = 'WebFOCUS';

GRAPH FILE A1
SUM COMPUTE PCT/D8.2% = IF TOTCAR NE 0 THEN NBCAR / TOTCAR * 100 ELSE 0; AS 'PERCENTAGE'
BY COUNTRY

WHERE COUNTRY EQ &COUNTRY.(OR(FIND CAR.COUNTRY IN CAR |FORMAT=A23V,SORT=ASCENDING)).COUNTRY:.;

ON GRAPH PCHOLD FORMAT JSCHART
ON GRAPH SET VZERO OFF
ON GRAPH SET GRWIDTH 1
ON GRAPH SET UNITS &WF_STYLE_UNITS
ON GRAPH SET HAXIS &WF_STYLE_WIDTH
ON GRAPH SET VAXIS &WF_STYLE_HEIGHT
ON GRAPH SET LOOKGRAPH PIE
ON GRAPH SET AUTOFIT ON
ON GRAPH SET STYLE *
*GRAPH_SCRIPT
setPieDepth(0);
setPieTilt(0);
setCurveFitEquationDisplay(false);
setPlace(true);
*END
INCLUDE=IBFS:/FILE/IBI_HTML_DIR/ibi_themes/Warm.sty,\$
TYPE=REPORT, TITLETEXT=&WF_TITLE.QUOTEDSTRING, \$
TYPE=DATA, COLUMN=N1, BUCKET=color, \$
TYPE=DATA, COLUMN=N2, BUCKET=measure, \$
*GRAPH_SCRIPT
setReportParsingErrors(false);
setSelectionEnableMove(false);
setDisplay(getLegendArea(),false);

setFillColor(getSeries(0), new Color(255,255,255));
setFillColor(getSeries(1), new Color(255,255,255));
setFillColor(getSeries(2), new Color(255,255,255));
setFillColor(getSeries(3), new Color(255,255,255));
setFillColor(getSeries(4), new Color(255,255,255));

-IF &COUNTRY CONTAINS 'ENGLAND'   THEN CONTINUE ELSE GOTO NOCLR1;
setFillColor(getSeries(0), new Color(200,200,200));
-NOCLR1

-IF &COUNTRY CONTAINS 'FRANCE'    THEN CONTINUE ELSE GOTO NOCLR2;
setFillColor(getSeries(1), new Color(255,0,0));
-NOCLR2

-IF &COUNTRY CONTAINS 'ITALY'     THEN CONTINUE ELSE GOTO NOCLR3;
setFillColor(getSeries(2), new Color(0,255,255));
-NOCLR3

-IF &COUNTRY CONTAINS 'JAPAN'     THEN CONTINUE ELSE GOTO NOCLR4;
setFillColor(getSeries(3), new Color(0,0,255));
-NOCLR4

-IF &COUNTRY CONTAINS 'W GERMANY' THEN CONTINUE ELSE GOTO NOCLR5;
setFillColor(getSeries(4), new Color(100,100,100));
-NOCLR5

*GRAPH_JS_FINAL
"pieProperties": {
holeSize: "40%",
totalLabel: {visible: true, font: 'Bold 12pt Sans-Serif', color: 'rgb(8,97,74)', numberFormat: '{{auto}}'}
},
"agnosticSettings": {
"chartTypeFullName": "Pie_Multi"
}
*END
ENDSTYLE
END
-RUN
```

WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007

 Posts: 2392 | Location: Montreal Area, Qc, CA | Registered: September 25, 2013 IP