私はそれを考え出した。以下のコードは、指定した背景色とグレーの色合いをブレンドします。次に、ブレンドされた色をグリッド線の色として使用します。
私はこれらからいくつかのヒント/コード/アイデアを取りました:
これを行うには、いくつかのユーティリティ マクロが必要です。
**
** MACRO TO CONVERT RGB->HEX
*;
%macro rgb_to_hex(iR=,iG=,iB=);
%local r g b hex;
%let r=%sysfunc(round(&iR,1));
%let g=%sysfunc(round(&iG,1));
%let b=%sysfunc(round(&iB,1));
%let hex = CX%sysfunc(putn(&r,hex2.))%sysfunc(putn(&g,hex2.))%sysfunc(putn(&b,hex2.));
&hex
%mend;
**
** MACRO TO CONVERT HEX->RGB. RESULTS ARE SAVED TO THE SPECIFIED MACRO VARIABLES
*;
%macro hex_to_rgb(iHex=, iRedMacroVar=rr, iGreenMacroVar=gg, iBlueMacroVar=bb);
%global &iRedMacroVar &iGreenMacroVar &iBlueMacroVar;
%local r g b;
%let r=%substr(&iHex,3,2);
%let g=%substr(&iHex,5,2);
%let b=%substr(&iHex,7,2);
%let &iRedMacroVar = %sysfunc(putn(%sysfunc(inputn(&r,hex2.)),z3.));
%let &iGreenMacroVar = %sysfunc(putn(%sysfunc(inputn(&g,hex2.)),z3.));
%let &iBlueMacroVar = %sysfunc(putn(%sysfunc(inputn(&b,hex2.)),z3.));
%mend;
**
** MACRO TO BLEND COLORS TOGETHER.
*;
%macro blend_colors(iHexColor1=, iHexColor2=, iBlendType=average);
%local blended;
%hex_to_rgb(iHex=&iHexColor1, iRedMacroVar=r1, iGreenMacroVar=g1, iBlueMacroVar=b1)
%hex_to_rgb(iHex=&iHexColor2, iRedMacroVar=r2, iGreenMacroVar=g2, iBlueMacroVar=b2)
%if "%upcase(&iBlendType)" eq "AVERAGE" %then %do;
%let blended = %rgb_to_hex(iR=%qsysfunc(round((&r1 + &r2) / 2,1)),
iG=%qsysfunc(round((&g1 + &g2) / 2,1)),
iB=%qsysfunc(round((&b1 + &b2) / 2,1)));
%end;
%else %if "%upcase(&iBlendType)" eq "ADDITIVE" %then %do;
%let blended = %rgb_to_hex(iR=%sysfunc(min(&r1 + &r2, 255)),
iG=%sysfunc(min(&g1 + &g2, 255)),
iB=%sysfunc(min(&b1 + &b2, 255)));
%end;
%else %do;
%put %str(E)RROR: (MACRO.BLEND_COLORS.SAS): INCORRECT PARAMETER PASSED IN FOR IBLENDTYPE.;
%end;
&blended
%mend;
コードは次のとおりです。
**
** PARAMETERS - SPECIFY A BACKGROUND COLOR AND THE AMOUNT OF GREY TO BLEND AGAINST IT
*;
* EXAMPLE1;
%let bg_color = CX000000; *BLACK;
%let grid_color = CX202020; *JUST A LITTLE GREY NEEDED;
* EXAMPLE2;
/*%let bg_color = CX0FF000; *GREEN;*/
/*%let grid_color = CX080808; * VERY LITTLE GREY NEEDED;*/
/** EXAMPLE3;*/
/*%let bg_color = CXFF0000; *RED;*/
/*%let grid_color = CX363636; *STRONGER GREY NEEDED;*/
**
** YOU COULD ALSO SPECIFY COLORS USING RGB IF YOU PREFER.
** USING THE BELOW COMMENTED OUT SYNTAX
*;
/*%let bg_color = %rgb_to_hex(iR=0 ,iG=0 ,iB=0 );*/
/*%let grid_color = %rgb_to_hex(iR=20 ,iG=20 ,iB=20);*/
**
** BLEND THE COLORS TOGETHER
*;
%let blended = %blend_colors(iHexColor1=&bg_color, iHexColor2=&grid_color, iBlendType=additive);
**
** TAKE THE DEFAULT STYLE BEING USED. MODIFY IT SO THAT
** GRAPH GRIDLINES WILL BE GREEN AND MOSTLY TRANSPARENT
*;
proc template;
define style my_style;
parent = styles.default;
style GraphGridLines from GraphGridLines / contrastcolor=&blended; * USE THE BLENDED COLOR AS THE GRID COLOR;
end;
run;
**
** LAYOUT TEMPLATE FOR A SIMPLE SERIES CHART
*;
proc template;
define statgraph mychart;
begingraph;
layout overlay / wallcolor=&bg_color
xaxisopts=(display=(line) griddisplay=on)
yaxisopts=(display=(line))
;
seriesplot x=name y=height / lineattrs=(color=white);
endlayout;
endgraph;
end;
run;
**
** PLOT SAMPLE DATA USING CUSTOM STYLE AND CHART LAYOUT WE JUST DEFINED
*;
ods graphics / width=640 height=640 ;
ods html style=my_style;
proc sgrender data=sashelp.class template=mychart;
run;
ods html close;