Data visualization with SAS programming

How Can I Assign a Custom Color set to Gchart lines?

Accepted Solution Solved
Reply
Super Contributor
Posts: 465
Accepted Solution

How Can I Assign a Custom Color set to Gchart lines?

How can I assign a custom color set to gchart lines?  I’m using indexes with proc template.  (Using Enterprise Gude.)


Accepted Solutions
Solution
‎05-23-2016 03:17 PM
Super Contributor
Posts: 465

Re: How Can I Assign a Custom Color set to Gchart lines?

data test2;                                                                                                                             

  set sashelp.workers;                                                                                                                  

  if electric > 270 then grouping =1;                                                                                                   

  else if electric > 255 then grouping =2;                                                                                              

  else grouping =3;                                                                                                                     

run;                                                                                                                                    

                                                                                                                                        

proc template;                                                                                                                          

  define statgraph layoutoverlay;                                                                                                       

/* Define the attributes for the data groups */                                                                                         

  begingraph / datacolors=(pink brown orange)                                                                                           

               datacontrastcolors=(pink brown orange)                                                                                   

               datalinepatterns=(1 1 1)                                                                                                 

               datasymbols=(CircleFilled TriangleFilled SquareFilled);                                                                  

                                                                                                                                        

    entrytitle "Trends in Employment Levels";                                                                                           

    entrytitle "Electrical";                                                                                                            

    layout overlay / cycleattrs=true                                                                                                    

           xaxisopts=(display=(ticks tickvalues))                                                                                       

           yaxisopts=(label="Number of Workers (thousands)");                                                                           

      seriesplot x=date y=electric / group=grouping;                                                                                    

    endlayout;                                                                                                                          

  endgraph;                                                                                                                             

  end;                                                                                                                                  

run;                                                                                                                                    

                                                                                                                                        

proc sgrender data=test2 template=layoutoverlay;                                                                                        

run;   

View solution in original post


All Replies
SAS Super FREQ
Posts: 888

Re: How Can I Assign a Custom Color set to Gchart lines?

Are you talking about gchart outlines? Can you send a code snippit?

Super Contributor
Posts: 465

Re: How Can I Assign a Custom Color set to Gchart lines?

I need to reword my question doing some research.

Grand Advisor
Posts: 10,194

Re: How Can I Assign a Custom Color set to Gchart lines?

I wouldn't normally associate GCHART with lines, usually that would be GPLOT. In which case SYMBOL1 through SYMBOL255 are available to assign line characteristics such as color, line type (various dash dot combinations) and thickness.

Super Contributor
Posts: 465

Re: How Can I Assign a Custom Color set to Gchart lines?

data test2; set sashelp.workers;
if electric > 270 then grouping =1;
else if electric > 255 then grouping =2;
else grouping =3;
run;

proc print data=sashelp.workers;
run;
proc template;
define statgraph layoutoverlay;
begingraph;
entrytitle "Trends in Employment Levels";
layout overlay / cycleattrs=true
xaxisopts=(display=(ticks tickvalues))
yaxisopts=(label="Number of Workers (thousands)");
seriesplot x=date y=electric / group=grouping
curvelabel="Electrical"
curvelabellocation=outside;
endlayout;
endgraph;
end;
run;
proc sgrender data=test2 template=layoutoverlay;
run;

 

In this example I want to define the first line as purple then yellow then orange.

Super Contributor
Posts: 465

Re: How Can I Assign a Custom Color set to Gchart lines?

[ Edited ]

I'm trying to merge two template ideas together.  One for colors and one for the graph.  Not sure on the syntax.

 

data test2; set sashelp.workers;
if electric > 270 then grouping =1;
else if electric > 255 then grouping =2;
else grouping =3;
run;

/*proc print data=sashelp.workers;
run;*/
proc template;



define statgraph layoutoverlay;
parent=styles.listing;
style GraphData1 /
ContrastColor=pink
Color=pink
MarkerSymbol="CircleFilled"
Linestyle=1;
style GraphData2 /
ContrastColor=brown
Color=brown
MarkerSymbol="TriangleFilled"
Linestyle=1;
style GraphData3 /
ContrastColor=orange
Color=orange
MarkerSymbol="SquareFilled"
Linestyle=1;
begingraph;
entrytitle "Trends in Employment Levels";
layout overlay / cycleattrs=true
xaxisopts=(display=(ticks tickvalues))
yaxisopts=(label="Number of Workers (thousands)");
seriesplot x=date y=electric / group=grouping
curvelabel="Electrical"
curvelabellocation=outside;
endlayout;
endgraph;
end;
run;

 

proc sgrender data=test2 template=layoutoverlay;
run;

Solution
‎05-23-2016 03:17 PM
Super Contributor
Posts: 465

Re: How Can I Assign a Custom Color set to Gchart lines?

data test2;                                                                                                                             

  set sashelp.workers;                                                                                                                  

  if electric > 270 then grouping =1;                                                                                                   

  else if electric > 255 then grouping =2;                                                                                              

  else grouping =3;                                                                                                                     

run;                                                                                                                                    

                                                                                                                                        

proc template;                                                                                                                          

  define statgraph layoutoverlay;                                                                                                       

/* Define the attributes for the data groups */                                                                                         

  begingraph / datacolors=(pink brown orange)                                                                                           

               datacontrastcolors=(pink brown orange)                                                                                   

               datalinepatterns=(1 1 1)                                                                                                 

               datasymbols=(CircleFilled TriangleFilled SquareFilled);                                                                  

                                                                                                                                        

    entrytitle "Trends in Employment Levels";                                                                                           

    entrytitle "Electrical";                                                                                                            

    layout overlay / cycleattrs=true                                                                                                    

           xaxisopts=(display=(ticks tickvalues))                                                                                       

           yaxisopts=(label="Number of Workers (thousands)");                                                                           

      seriesplot x=date y=electric / group=grouping;                                                                                    

    endlayout;                                                                                                                          

  endgraph;                                                                                                                             

  end;                                                                                                                                  

run;                                                                                                                                    

                                                                                                                                        

proc sgrender data=test2 template=layoutoverlay;                                                                                        

run;   
Super Contributor
Posts: 465

Re: How Can I Assign a Custom Color set to Gchart lines?

[ Edited ]

Turns out I actually need to do the same thing with gchart bars.  This is done with Patern statements.

Super Contributor
Posts: 465

Re: How Can I Assign a Custom Color set to Gchart lines?

[ Edited ]

According to:

http://support.sas.com/documentation/cdl/en/grstatproc/67909/HTML/default/viewer.htm#p1dt33l6a6epk6n...

I need group = panelBy3 for colors to show up here?  Can I have the same first color without the group?

 

data test2;                                                                                                                             

  set sashelp.workers;                                                                                                                  

  if electric > 270 then grouping =1;                                                                                                   

  else if electric > 255 then grouping =2;                                                                                              

  else grouping =3;                                                                                                                     

  if electric > 270 then panelBy1 =1;                                                                                                   

  else if electric > 255 then panelBy1 =2;                                                                                              

  else panelBy1 =3;   

  if electric > 270 then panelBy2 =1;                                                                                                   

  else if electric > 255 then panelBy2 =2;                                                                                              

  else panelBy2 =3; 

  if electric > 270 then panelBy3 =1;                                                                                                   

  else if electric > 255 then panelBy3 =2;                                                                                              

  else panelBy3 =3; 

run; 

proc sgpanel data=test2 ;
	panelby panelBy1 panelBy2 / layout=lattice uniscale=column novarname columns=4 onepanel headerbackcolor="969491" HEADERATTRS=(Weight=Bold color=white);
	styleattrs datacontrastcolors=(CXFFBA00 black CX969491 CX6341 CX63513D CX768692 CX69B3E7 CX6BCABA CXC6AA76 CXE9DF97 CXC4D600 CXE57200) 
	datacolors=(CXFFBA00 black CX969491 CX6341 CX63513D CX768692 CX69B3E7 CX6BCABA CXC6AA76 CXE9DF97 CXC4D600 CXE57200);
	vbar grouping / response=electric nostatlabel grouporder=ascending group = panelBy3;

 

 

 for a single color use: vbar grouping / response=electric nostatlabel fillattrs=(color=CXFFBA00);

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 478 views
  • 2 likes
  • 3 in conversation