Focal Point
[Undecided]Graph Value Color

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

April 02, 2009, 11:38 AM
Prarie
[Undecided]Graph Value Color
I've searched and not finding my answer. I have a series of about 25 Stacked Bar Graphs graphs...using the same data in different ways. Everything is based on a Reason Code with about 15 differnt values. Some graphs may have only 3 reason codes ploted, some might have all 15. The user would like the Reasons to always be the same color. For instance..Reason 'FELL OFF THE BOAT' should always be Red. Reason "SUNK THE BOAT' Should always be Green and so on. I need to be able to control the setfillcolor based on the value of the Reason, not the Series or Group.

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


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
Prarie,

It's my guess that there is no way to do that via conventional means, but you could use WebFOCUS to generate the Java colour coding lines. This would unfortunately mean going through the data twice, once to produce the Java colour coding lines and once to produce the graph.

Here's a quick example that seems to work:

-*-- graph_fixed_colour.fex --------------------------------

-SET &ECHO='ALL';

SET ASNAMES=ON
SET HOLDLIST=PRINTONLY
SET HOLDFORMAT=ALPHA
-RUN

DEFINE FILE CAR
JAVACOLOR1/A23 = 'setFillColor(getSeries(';
JAVACOLOR2/A12 = '),new Color(';
JAVACOLOR3/A03 = '));';
COUNTRY_COLOUR/A11 = DECODE COUNTRY (
'ENGLAND'   '255,0,0'  ,
'FRANCE'    '0,255,0'  ,
'ITALY'     '0,0,255'  ,
'JAPAN'     '0,255,255',
'W GERMANY' '255,255,0',
ELSE        '255,0,255');
END
-RUN

TABLE FILE CAR
SUM
COMPUTE COUNTRY_COUNTA/D6 = COUNTRY_COUNTA + 1; NOPRINT
COMPUTE COUNTRY_COUNTB/D6 = COUNTRY_COUNTA - 1; NOPRINT
COMPUTE COUNTRY_COUNTC/A6 = STRIP(6, FTOA(COUNTRY_COUNTB, '(D6c)', 'A6'), ' ', 'A6'); NOPRINT
COMPUTE JAVACOLOURA/A200  =
  JAVACOLOR1 || COUNTRY_COUNTC || JAVACOLOR2 || COUNTRY_COLOUR || JAVACOLOR3;

BY COUNTRY NOPRINT

WHERE COUNTRY NE 'ENGLAND'

ON TABLE HOLD AS HJAVACOLOUR
END
-RUN

GRAPH FILE CAR
SUM
SALES

BY COUNTRY

WHERE COUNTRY NE 'ENGLAND'

ON GRAPH SET GRAPHSTYLE *
-INCLUDE HJAVACOLOUR
ENDSTYLE
END


As long as the same filters are used in both passes though the data, this should work.

Try excluding a different Country and rerun the graph - England is always red, Germany is always yellow...

I realize this is a very simple graph and you may not be able to do this in a complex one.

The Country colour could be in an INCLUDE to standardize the colours used, so could some of the other code generating the Java colour coding lines.

Hopefully this gives you an idea or three...


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
Thanks Francis...that is very interesting and brings up a lot of possiblities..but I'm afraid I'm lost on what Country_count computes are for?
I'm sorry I gave no explanations! If you "View Source" you'll see that the Java colour coding lines look like this:

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


There's one line for every graph object(?), from zero to 99. The computes just create the 0, 1, 2, 3... The first compute creates 1, 2, 3, 4... The second compute subtracts 1 from the value to get 0, 1, 2, 3... The third converts the value to alpha and strips the leading blanks. This is then used in the final compute to generate the Java colour coding line.

Run this code to see what happens:

-SET &ECHO='ALL';

SET ASNAMES=ON
SET HOLDLIST=PRINTONLY
SET HOLDFORMAT=ALPHA
-RUN

DEFINE FILE CAR
JAVACOLOR1/A23 = 'setFillColor(getSeries(';
JAVACOLOR2/A12 = '),new Color(';
JAVACOLOR3/A03 = '));';
COUNTRY_COLOUR/A11 = DECODE COUNTRY (
'ENGLAND'   '255,0,0'  ,
'FRANCE'    '0,255,0'  ,
'ITALY'     '0,0,255'  ,
'JAPAN'     '0,255,255',
'W GERMANY' '255,255,0',
ELSE        '255,0,255');
END
-RUN

TABLE FILE CAR
SUM
COMPUTE COUNTRY_COUNTA/D6 = COUNTRY_COUNTA + 1;
COMPUTE COUNTRY_COUNTB/D6 = COUNTRY_COUNTA - 1;
COMPUTE COUNTRY_COUNTC/A6 = STRIP(6, FTOA(COUNTRY_COUNTB, '(D6c)', 'A6'), ' ', 'A6');
COMPUTE JAVACOLOURA/A200  =
  JAVACOLOR1 || COUNTRY_COUNTC || JAVACOLOR2 || COUNTRY_COLOUR || JAVACOLOR3;

BY COUNTRY NOPRINT

-*WHERE COUNTRY NE 'W GERMANY'

-*ON TABLE HOLD AS HJAVACOLOUR
END
-RUN
-EXIT



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
Ok...I get it...let me play and see what I can do. Thanks...I'll report back.
I'm doing this with the following code

GRAPH FILE.....
SUM FIELD1
CHECKVALUE NOPRINT
BY FILED2
ACROSS FIELD3
.....
ENDSTYLE
ON GRAPH SET STYLE *
DEFMACRO=Condition_1, COLOR=RGB(0 100 0), WHEN=N3 EQ 'Y', $
DEFMACRO=Condition_2, COLOR=RGB(255 215 0), WHEN=N3 EQ 'N', $
TYPE=DATA, ACROSSCOLUMN=N1, MACRO=Condition_1, $
TYPE=DATA, ACROSSCOLUMN=N1, MACRO=Condition_2, $
ENDSTYLE

I'm graphing a 4 series, but only show two colors depending on another field that I don't display.


Check out th Applying Conditional Styling to a graph section of the Creating Reports with WebFOCUS Language....

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


Laure


Prod: WebFOCUS 7.7.03 - MRE, BID, - WindowsXP - Oracle 9i, SQLServer, DevStudio 7.7.3 - Apache Tomcat , Output: HTML, Excel 2013 and PDF
That makes things a lot easier! Merci Laure!

-SET &ECHO='ALL';

GRAPH FILE CAR
SUM
COUNTRY NOPRINT
SALES

ACROSS COUNTRY

-*WHERE COUNTRY NE 'W GERMANY'

ON GRAPH SET STYLE *
TYPE=REPORT, ACROSSCOLUMN=SALES, COLOR=RGB(255 0 255), $
TYPE=REPORT, ACROSSCOLUMN=SALES, COLOR=RGB(255 0 255), $
TYPE=REPORT, ACROSSCOLUMN=SALES, COLOR=RGB(255 0 0)  , WHEN= COUNTRY EQ 'ENGLAND'  , $
TYPE=REPORT, ACROSSCOLUMN=SALES, COLOR=RGB(0 255 0)  , WHEN= COUNTRY EQ 'FRANCE'   , $
TYPE=REPORT, ACROSSCOLUMN=SALES, COLOR=RGB(0 0 255)  , WHEN= COUNTRY EQ 'ITALY'    , $
TYPE=REPORT, ACROSSCOLUMN=SALES, COLOR=RGB(0 255 255), WHEN= COUNTRY EQ 'JAPAN'    , $
TYPE=REPORT, ACROSSCOLUMN=SALES, COLOR=RGB(255 255 0), WHEN= COUNTRY EQ 'W GERMANY', $
ENDSTYLE
END



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
Well I had already done Fransis method when i saw the other tip..and now I have control of my colors...but I have no legend anymore. Confused
The method I posted, while it will display a legend, I haven't been able to control the colors. They default. Maybe someone else has been able to do this?


Laure


Prod: WebFOCUS 7.7.03 - MRE, BID, - WindowsXP - Oracle 9i, SQLServer, DevStudio 7.7.3 - Apache Tomcat , Output: HTML, Excel 2013 and PDF
You need to add

ON GRAPH SET GRAPHSTYLE *
setDepthRadius(0);
setSeriesAreRows(false);
setLegendDisplay(true);
setPlace(true);
ENDSTYLE
Francis,
Your code works great and I'm looking to adapt it to keep static colors for multiple graphs shown on the same BID page and display those same colors in the legend which my . The issue I'm having is that I can not get your code to run under MRE. The -INCLUDE looks for a FEX and gives me an error.

Error occurred.
ERROR: ERROR_MR_FEX_NOT_FOUND Can't create item object based on provided item key HJAVACOLOUR.fex.

I've tried setting the APP HOLD to the application folder and then doing
-INCLUDE APP/HJAVACOLOUR

but still I get the same error. Do you have a suggestion on how to get around MRE looking for a .FEX on the -INCLUDE?


Laure


Prod: WebFOCUS 7.7.03 - MRE, BID, - WindowsXP - Oracle 9i, SQLServer, DevStudio 7.7.3 - Apache Tomcat , Output: HTML, Excel 2013 and PDF
Hi Laurie,

Just put -MRNOEDIT in front of the -INCLUDE. Works in 7.6.8:

-MRNOEDIT -INCLUDE HJAVACOLOUR

Say HI to everyone...Tom


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
Thanks, I was just testing with the MRNOEDIT when you email popped in.

I'll pass on the hello to the gang.


Laure


Prod: WebFOCUS 7.7.03 - MRE, BID, - WindowsXP - Oracle 9i, SQLServer, DevStudio 7.7.3 - Apache Tomcat , Output: HTML, Excel 2013 and PDF
I have never been able to make this work properly...will keep playing. My Graphs are quite complex...with Loops and stuff. Frowner
I'm back.

I have never been able to get this to work. Here is what I have below. Some of the graphs may have only 3 reasons...some may have all of them. So the colors are never consistant.
Any other thoughts on this?

DEFINE FILE DEM_HOLD1 ADD
JAVACOLOR1/A23 = 'setFillColor(getSeries(';
JAVACOLOR2/A12 = '),new Color(';
JAVACOLOR3/A03 = '));';
REASON_COLOUR/A11 = DECODE DEMURRAGE_REASON_DEF (
'COMMERCIAL DECISION' '455,0,0' ,
'CONTRACT ISSUE' '0,255,500' ,
'LIGHTERING OPERATIONS' '400,0,255' ,
'DESPATCH' '0,255,455',
'PORT/WATERWAY RESTRICTION' '655,255,0',
'PRODUCT NOT AVAIL' '0,50,750' ,
'CONTRACT ISSUE' '0,500,200' ,
'LIGHTERING OPERATIONS' '0,150,350' ,
'PRODUCT QUALITY' '0,400,100',
'PRODUCT TOO HOT' '0,650, 50',
'SHORE PERSONNEL' '50,0,850',
'CONTRACT ISSUE' '600,0,200',
'TERM VESSEL IDLE TIME' '150,0,450',
'TRUCK CONGESTION' '600,0,100',
'VALERO DOCK: BERTH NOT AV' '250,0,80',
'VALERO SHORE OPERATIONS' '450,250, 50' ,
'VALERO TANK NOT AVAILABLE' '50, 50, 50' ,
'LIGHTERING OPERATIONS' '100,100,100' ,
'VESSEL ISSUES' '150,150,150',
'WEATHER' '200,200,200',
ELSE '0, 0,250' );
END
TABLE FILE DEM_HOLD1
SUM

COMPUTE COUNTRY_COUNTA/D8 = COUNTRY_COUNTA + 1; NOPRINT
COMPUTE COUNTRY_COUNTB/D8 = COUNTRY_COUNTA - 1; NOPRINT
COMPUTE COUNTRY_COUNTC/A8 = STRIP(8, FTOA(COUNTRY_COUNTB, '(D8c)', 'A8'), ' ', 'A8'); NOPRINT
COMPUTE JAVACOLOURA/A200 =
JAVACOLOR1 || JAVACOLOR2 || REASON_COLOUR || JAVACOLOR3;

BY DEMURRAGE_REASON_DEF NOPRINT
ON TABLE HOLD AS JAVACOLOX
END
TABLE FILE JAVACOLOX
PRINT JAVACOLOURA
ON TABLE HOLD AS JAVACOLOR
END
Try adding the COUNTRY_COUNTC into the concatenation and holding format ALPHA

  
COMPUTE JAVACOLOURA/A200 =
JAVACOLOR1 || COUNTRY_COUNTC  || JAVACOLOR2 || REASON_COLOUR || JAVACOLOR3;
ON TABLE HOLD AS HJAVAC FORMAT ALPHA
END 



Then
GRAPH FILE....

ON GRAPH SET GRAPHSTYLE *
-MRNOEDIT BEGIN
-INCLUDE HJAVAC
-MRNOEDIT END
....
END



Laure


Prod: WebFOCUS 7.7.03 - MRE, BID, - WindowsXP - Oracle 9i, SQLServer, DevStudio 7.7.3 - Apache Tomcat , Output: HTML, Excel 2013 and PDF
Good Eye.
Wink


I did have it that way...and tried it this way right before I cut and paste...didnt' make a difference either way...