Sample 25514: Creating drill-down bar charts for the web using PROC GCHART
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample is from the "SAS/GRAPH Software: Reference, Version 8", Volume 1, Chapter 13.
For additional information on the sample refer to this book.
/*+-------------------------------------------------------------+
| S A S S A M P L E L I B R A R Y |
| |
| NAME: GCHDDOWN |
| TITLE: GCHDDOWN-Creating Drill-down Bar Charts for the Web|
| PRODUCT: GRAPH |
| SYSTEM: ALL |
| KEYS: GRAPHICS AXIS PATTERN GCHART ODS |
| PROCS: GCHART |
| DATA: INTERNAL |
| |
| SUPPORT: GRAPHICS STAFF UPDATE: |
| REF: SAS/GRAPH REFERENCE GUIDE |
| MISC: FOR CMS, CHANGE FILENAME SPECIFICATIONS FOR |
| ODS STATEMENTS |
| |
| USE grain_frame.html TO SEE THE RESULTS IN YOUR |
| BROWSER |
+-------------------------------------------------------------+*/
/* Define a fileref for the destination for graphics output */
*filename odsout 'path to web server space';
/* Stops sending output to GRAPH and OUTPUT windows */
ods listing close;
/* Set selected graphics options for the examples */
goptions reset=all gunit=pct
htitle=6 htext=4 ftitle=zapfb ftext=swiss;
/* Create the data set GRAINLDR */
data grainldr;
length country $ 3 type $ 5;
input year country $ type $ amount;
megtons=amount/1000;
datalines;
1995 BRZ Wheat 1516
1995 BRZ Rice 11236
1995 BRZ Corn 36276
1995 CHN Wheat 102207
1995 CHN Rice 185226
1995 CHN Corn 112331
1995 IND Wheat 63007
1995 IND Rice 122372
1995 IND Corn 9800
1995 INS Wheat .
1995 INS Rice 49860
1995 INS Corn 8223
1995 USA Wheat 59494
1995 USA Rice 7888
1995 USA Corn 187300
1996 BRZ Wheat 3302
1996 BRZ Rice 10035
1996 BRZ Corn 31975
1996 CHN Wheat 109000
1996 CHN Rice 190100
1996 CHN Corn 119350
1996 IND Wheat 62620
1996 IND Rice 120012
1996 IND Corn 8660
1996 INS Wheat .
1996 INS Rice 51165
1996 INS Corn 8925
1996 USA Wheat 62099
1996 USA Rice 7771
1996 USA Corn 236064
;
/* Add the HTML variables to the data set */
data newgrain;
set grainldr;
length yeardrill typedrill countrydrill $ 40;
/* Assign targets for YEAR values */
if year=1995 then
yeardrill='HREF="year95_body.html"';
else if year=1996 then
yeardrill='HREF="year96_body.html"';
/* Assign targets for COUNTRY values */
if country='BRZ' then
countrydrill='HREF="country_body.html#country"';
else if country='CHN' then
countrydrill='HREF="country_body.html#country1"';
else if country='IND' then
countrydrill='HREF="country_body.html#country2"';
else if country='INS' then
countrydrill='HREF="country_body.html#country3"';
else if country='USA' then
countrydrill='HREF="country_body.html#country4"';
/* Assign targets for TYPE values */
if type='Corn' then
typedrill='HREF="type1_body.html"';
else if type='Rice' then
typedrill='HREF="type2_body.html"';
else if type='Wheat' then
typedrill='HREF="type3_body.html"';
run;
proc format;
value $country 'BRZ' = 'Brazil'
'CHN' = 'China'
'IND' = 'India'
'INS' = 'Indonesia'
'USA' = 'United States';
run;
/* Define patterns for all graphs */
pattern1 color=blue;
pattern2 color=green;
pattern3 color=cyan;
/* Define legend characteristics for all legends */
legend1 label=none
shape=bar(4,4)
position=(bottom center)
offset=(-3);
/* Define goptions for ods html processing */
goptions transparency device=gif noborder;
/* Open ODS HTML files */
ods html body='grain_body.html'
frame='grain_frame.html'
contents='grain_contents.html'
path=odsout
nogtitle;
/******************* Part A **********************/
/* Suppress the midpoint label and values */
axis1 label=none value=none;
/* Modify the response axis label */
axis2 label=(angle=90 'Metric Tons (millions)')
minor=(n=1)
order=(0 to 500 by 100)
offset=(0,0);
/* Modify the group axis */
axis3 label=none
order=('China' 'United States' 'India'
'Indonesia' 'Brazil')
split=' ';
/* Define titles and footnote */
title1 'Corn, Rice, and Wheat Production';
title2 h=2 'Leading Producers for 1995 and 1996';
footnote1 j=l h=3 'click on bars or legend values' j=r h=3 'GRAINALL ';
/* Produce first bar chart: totals for all countries */
proc gchart data=newgrain;
format country $country.;
vbar3d year / discrete
sumvar=megtons
group=country
subgroup=year
html=countrydrill
html_legend=yeardrill
cframe=grayaa
space=0
width=4
gspace=5
maxis=axis1
raxis=axis2
gaxis=axis3
coutline=black
legend=legend1
name='grainall'
des='Overview of Leading Grain Producers';
run;
/******************** Part B *********************/
/* Produce two bar charts of year: countries subrouped by type*/
/* Open a new body for the graph of 1995 */
/* Specify the anchor name */
ods html body='year95_body.html' path=odsout;
/* title and footnote for 1995 graph */
title1 'Total Production for 1995';
footnote1 j=l h=3 'click on bars or legend values' j=r 'YEAR95 ';
/* Produce bar chart for 1995 */
where year=1995;
vbar3d country / sumvar=megtons
subgroup=type
autoref
html=countrydrill
html_legend=typedrill
legend=legend1
cframe=grayaa
space=3
coutline=black
maxis=axis3
raxis=axis2
name='year95'
des='Production Breakdown for 1995';
run;
/* Open a new body for the graph of 1995 */
/* Specify the anchor name */
ods html body='year96_body.html' path=odsout;
/* title and footnote for 1996 graph */
title1 'Total Production for 1996';
footnote1 j=l h=3 'click on bars or legend values' j=r 'YEAR96 ';
/* Produce bar chart for 1996 */
where year=1996;
vbar3d country / sumvar=megtons
subgroup=type
autoref
html=countrydrill
html_legend=typedrill
legend=legend1
cframe=grayaa
space=3
coutline=black
maxis=axis3
raxis=axis2
name='year96'
des='Production Breakdown for 1996';
run;
quit;
/*********************** Part C **********************/
/* Sort the data by country */
proc sort data=newgrain out=country;
by country;
run;
/* Open a new body for the breakdown by country */
/* Specify the base anchor name */
ods html body='country_body.html'
anchor='country'
gfootnote
path=odsout;
/* Redefine AXIS2 to remove all axis elements */
axis2 order=(0 to 250 by 50)
label=none
value=none
style=0
major=none
minor=none
noplane;
/* Suppress the axis label */
axis4 label=none;
/* Suppress the BY-line */
options nobyline;
/* Define title and footnote */
title1 'Breakdown for #byval(country)';
footnote1 j=l h=3 'click on bars';
footnote2 j=c '(Millions of Metric Tons)';
proc gchart data=country;
format country $country.;
by country;
vbar3d year / discrete
sumvar=megtons
patternid=group
group=type
shape=hexagon
outside=sum
html=typedrill
width=9
gspace=3
space=0
cframe=grayaa
raxis=axis2
gaxis=axis4
maxis=axis4
name='country'
des='Grain and Year Breakdown';
run;
/*********************** Part D ****************************/
/* Sort the data by type */
proc sort data=grainldr out=type;
by type;
run;
/* Open a new body for the breakdown by type */
/* Specify the base anchor name */
ods html body='type1_body.html'
newfile=table
path=odsout;
/* Suppress the label and format the values */
axis5 label=none split=' ';
title1 'Top Three Producers of #byval(type)';
title2 '(In Millions of Metric Tons)';
footnote1 j=r h=3 'TYPE';
/* Produce series of bar charts: country and type */
proc gchart data=type (where=(megtons gt 31));
format country $country.;
by type;
vbar3d year / discrete
sumvar=megtons
group=country
nozero
shape=cylinder
noframe
patternid=group
inside=sum
width=8
maxis=axis4
raxis=axis2
gaxis=axis5
cframe=grayaa
name='type'
des='Leading Producers';
run;
quit;
ods html close;
ods listing;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This code produces an HTML file with drilldown capabilities.
Click here to see the frameset:
See the frameset
This example shows how to create 3D bar charts with drill-down functionality for the Web. In addition to showing how to use the ODS HTML statement and the HTML options to create the drill-down, the example also illustrates other VBAR3D statement options.
| Type: | Sample |
| Topic: | SAS Reference ==> ODS (Output Delivery System) SAS Reference ==> Procedures ==> GCHART Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Types ==> Charts ==> Bar
|
| Date Modified: | 2005-08-24 16:06:35 |
| Date Created: | 2005-05-23 14:12:32 |
Operating System and Release Information
| SAS System | SAS/GRAPH | All | 8 TS M0 | n/a |