Data visualization with SAS programming

inserting a background image for a gchart

Occasional Contributor
Posts: 15

inserting a background image for a gchart

I have created a bar chart using proc gchart with the relevant code below that produces this. However, I am wishing to add an image from a local drive that is a jpeg called 'log.jpeg' as a background to the chart and was wandering how to go about doing this. Cheers.



data methods_15;
input Method $ Percent ;
One 69.64
Two 79.73
Three 80.59
Four 80.83
Five 87.55


/* Set the graphics environment */                                                                                                      
goptions reset=all  cback=aliceblue htext=10pt htitle=12pt ctext=goldenrod noborder ;     

/* Create the Annotate data set*/                                                                                                       
data anno;                                                                                                                              
   length function color $8 style $12;                                                                                                  
   retain function 'label' when 'a' size 1.25 position '2'                                                                              
          color 'black' xsys '2' ysys '2' style 'Albany AMT';                                                                           
   set methods_15;                                                                                                                   
    where Method in ( 'One','Two','Three','Four','Five');                                                                              
   if Method in ('One','Two','Three','Four','Five') then color='blue';                                                                                         
text=put(Percent,4.1) ;
  axis1 label=(f='Albany AMT/bold' 'Method')
order=('One' 'Two' 'Three' 'Four' 'Five');
axis2 label=(f='Albany AMT/bold' '%');
/* Add a title to the graph */                                                                                                          
title 'Correct Classification';  

/*Colours for the bars - Note how it does it in alphabetical order */
Pattern1 color=lilg;
pattern2 color=lightorange;
pattern3 color=lightblue;
pattern4 color=lightred;
pattern5 color=lightblack;
/* Produce the bar chart */                                                                                                             
proc gchart data=methods_15;   
where Method in ( 'One','Two','Three','Four','Five');  
   vbar Method / sumvar=Percent annotate=anno                                                                                              
               patternid=midpoint width=10 maxis=axis1 raxis=axis2 autoref noframe cautoref=bippk;   




Posts: 490

Re: inserting a background image for a gchart

Super User
Posts: 21,917

Re: inserting a background image for a gchart

See the methods here with fully worked examples


Note, that if you have the option you should consider using SGPLOT instead. It creates better quality graphics with more options and easier to use. 

Super User
Posts: 12,316

Re: inserting a background image for a gchart

GCHART is designed to work with device graphics, orginally pens placed into holders on a plotter, and the newer SGPLOT does much more than gchart.


With that said, the options IFRAME= in the VBAR options, or IBACK = in a GOPTIONs statement, will include an image file by pointing to the location. Note: IFRAME is not supported by Java.

Posts: 997

Re: inserting a background image for a gchart

For completeness, I'll mention that the way to do this in SGPLOT is to use SG annotation. See pages 9-13 of my paper below to see what you can do with images. For the wall (iFRAME) case, you will need to turn the wall off (NOWALL option) to see the image through the wall area.


Hope this helps!



Ask a Question
Discussion stats
  • 4 replies
  • 5 in conversation