Focal Point
[WORKAROUND] Displaying bar graph with negative values

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/9207005306

May 09, 2011, 03:28 AM
Nivin
[WORKAROUND] Displaying bar graph with negative values
I have a bar graph which shows % change values. For example the difference in sales in the month of Jan for 2 consecutive years. Therefore the graph can have negative values. There are three adjacent bars, two showing the values for the years compared and the other showing the % change. This repeats as a series for other months.

If the % change is negative the bar displays in the negative direction. I want the bar to be displayed in the positive direction along side the other two bars.

Is this possible ?

Above problem was partially solved when i used the API setScaleFromZero(false). This displays the bars in the positive direction but the bars do not originate from the zero line instead from a level below, for example -80 as the case may be according to the % change value.

Is there a better approach ?

The next problem is with the display of the data text corresponding to the bars when setScaleFromZero(false) is used. I need them displayed at the top of the bars and so used setDataTextPosition(1) which should ideally position the data text values above the bars. But in this case if the value is negative it is displayed inside the bar, just below the top as in the case when setDataTextPosition(3) is used.

How can this be solved ?

This message has been edited. Last edited by: Nivin,


WebFOCUS 7.6
Windows, All Outputs
May 09, 2011, 10:58 AM
GamP
Beats me why you would want negative values to be displayed as positive, but it is not my place to question your motives.
What I would do in this specific case is to solve this programmatically. By that I mean to compute the percentage as an absolute value. That way it is always prositive, starts from the zero line and displays the values above the bar.


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
May 09, 2011, 12:16 PM
<JG>
I can see the logic when data text is displayed, however it does take away from the principle purpose of a graph which is instant visualization.

Using the ABS value means the data text value will also display as +ve.

As a work around plot the ABS value but color it conditionally.

GRAPH FILE CAR
-* Created by Advanced Graph Assistant
SUM  DEALER_COST
     RETAIL_COST
COMPUTE DIFF/D20=IF COUNTRY EQ 'JAPAN' THEN ( DCOST - RCOST ) ELSE RCOST - DCOST ; NOPRINT
COMPUTE DIFFA/D20= ABS(DIFF);
BY COUNTRY
ON GRAPH PCHOLD FORMAT PNG
ON GRAPH SET HTMLENCODE ON
ON GRAPH SET GRAPHDEFAULT OFF
ON GRAPH SET VZERO OFF
ON GRAPH SET HAXIS 770
ON GRAPH SET VAXIS 405
ON GRAPH SET UNITS PIXELS
ON GRAPH SET LOOKGRAPH VBAR
ON GRAPH SET GRMERGE ADVANCED
ON GRAPH SET GRMULTIGRAPH 0
ON GRAPH SET GRLEGEND 0
ON GRAPH SET GRXAXIS 1
ON GRAPH SET GRAPHSTYLE *
setTemplateFile("/images/tdg/template/IBISouthWestern.txt");
setReportParsingErrors(false);
setSelectionEnableMove(false);
setDepthRadius(5);
setTransparentBorderColor(getChartBackground(),true);
setTransparentBorderColor(getSeries(0),true);
setTransparentBorderColor(getSeries(1),true);
setTransparentBorderColor(getSeries(2),true);
setTransparentBorderColor(getSeries(3),true);
setTransparentBorderColor(getSeries(4),true);
setTransparentBorderColor(getSeries(5),true);
setTransparentBorderColor(getSeries(6),true);
setTransparentBorderColor(getSeries(7),true);
setTransparentBorderColor(getSeries(8),true);
setTransparentBorderColor(getSeries(9),true);
setTransparentBorderColor(getSeries(10),true);
setPlace(true);
setDisplay(getDataText(),true);
setDataTextPosition(1);
setUseNegativeDataTextColor(true);
ENDSTYLE
ON TABLE SET STYLE *
TYPE=DATA, COLUMN=N5, COLOR=RED, WHEN=N4 LT 0, $
ENDSTYLE
END  

May 10, 2011, 02:42 AM
Nivin
I have to bring in a small clarification here.

The negative values should not be displayed as positive, instead their corresponding bars should be in positive direction i.e rising upwards from the zero line x-axis instead of the general behaviour of downward display. The negative values should be displayed as negative values as associated data texts. Well.. um.. uh.. this is the requirement.


Infact i have used the ABS function with conditional styling and have actually reached the stage illustrated above. But since its the ABS-ed value that is being displayed all are displayed as positive. What i see as a possible solution is to append a minus sign to the actual negative values for display purpose alone.

Can this be done?


WebFOCUS 7.6
Windows, All Outputs
May 10, 2011, 03:42 AM
GamP
You may be able to get something done by playing around withthe text-pattern for the displayable values. I've been sort of partly successful doing this for a client, their requirement was to show a certain number of characters at a certain position in the vlaue when a certain condition applied. I achieved this for just one extra character at some position in the displayed value.
Hope this helps ...


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
May 10, 2011, 03:57 AM
FrankDutch
maybe the annotation function could help you with this




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

May 10, 2011, 04:36 AM
<JG>
Appears to be a bug on datatext positioning for -ve values

 
GRAPH FILE CAR
-* Created by Advanced Graph Assistant
SUM  DEALER_COST
     RETAIL_COST
COMPUTE DIFF/D20=IF COUNTRY EQ 'JAPAN' THEN ( DCOST - RCOST ) ELSE RCOST - DCOST ; 
BY COUNTRY
ON GRAPH PCHOLD FORMAT PNG
ON GRAPH SET HTMLENCODE ON
ON GRAPH SET GRAPHDEFAULT OFF
ON GRAPH SET VZERO OFF
ON GRAPH SET HAXIS 770
ON GRAPH SET VAXIS 405
ON GRAPH SET UNITS PIXELS
ON GRAPH SET GRMERGE ADVANCED
ON GRAPH SET GRMULTIGRAPH 0
ON GRAPH SET GRLEGEND 0
ON GRAPH SET GRXAXIS 1
ON GRAPH SET GRAPHSTYLE *
setTemplateFile("/images/tdg/template/IBISouthWestern.txt");
setReportParsingErrors(false);
setSelectionEnableMove(false);
setGraphType(19);
setDepthRadius(0);
setTransparentBorderColor(getChartBackground(),true);
setTransparentBorderColor(getSeries(0),true);
setTransparentBorderColor(getSeries(1),true);
setTransparentBorderColor(getSeries(2),true);
setTransparentBorderColor(getSeries(3),true);
setTransparentBorderColor(getSeries(4),true);
setTransparentBorderColor(getSeries(5),true);
setTransparentBorderColor(getSeries(6),true);
setTransparentBorderColor(getSeries(7),true);
setTransparentBorderColor(getSeries(8),true);
setTransparentBorderColor(getSeries(9),true);
setTransparentBorderColor(getSeries(10),true);
setPlace(true);

setAxisAssignment(getSeries(2), 1);
setGraphType(19);
setScaleFromZero(false);
setY1ScaleMax(60000);
setY2ScaleMax(60000);
setY1ScaleMaxAuto(false);
setY2ScaleMaxAuto(false);
setDisplay(getDataText(),true);
setDataTextPosition(1);
setDisplay(getY2AxisLine(),false);
setDisplay(getY2Label(),false);
ENDSTYLE

END  
 

May 10, 2011, 07:35 AM
Nivin
Hi GamP,

Can you post a sample code for a better understanding of how exactly conditional styling was employed on data text.

Was the styling done in the 'ON GRAPH SET GRAPHSTYLE *' section or 'ON GRAPH SET STYLE *'.

Does 'data text' have an equivalent keyword that can be used in the latter section ?


WebFOCUS 7.6
Windows, All Outputs
May 10, 2011, 08:42 AM
GamP
I did that on the GRAPHSTYLE part, using the advanced graph editor. Don't have the actual code available at this moment, I'll try to find it for you. Won't be today though...


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
May 10, 2011, 03:49 PM
GamP
It was something like this:
setTextFormatPattern(getDataText(1),"###,##0-");
setPlaceResize(getDataText(1),0);
setCustomDataText(getDataText(1),true);
It's how I managed to add a minus sign to the value displayed for the second series. I'm not exactly sure how to do this for only those values that are actually negative ...


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988