/*------------------------------------------------------------------- */
/* SAS Graphics for Java */
/* by Wendy Bohnenkamp and Jackie Iverson */
/* Copyright(c) 2004 by SAS Institute Inc., Cary, NC, USA */
/* ISBN 978-1-59047-693-2 */
/*-------------------------------------------------------------------*/
/* */
/* This material is provided "as is" by SAS Institute Inc. There */
/* are no warranties, expressed or implied, as to merchantability or */
/* fitness for a particular purpose regarding the materials or code */
/* contained herein. The Institute is not responsible for errors */
/* in this material as it now exists or will exist, nor does the */
/* Institute provide technical support for it. */
/* */
/*-------------------------------------------------------------------*/
/* Questions or problem reports concerning this material may be */
/* addressed to the author: */
/* */
/* SAS Institute Inc. */
/* Books by Users */
/* Attn: Wendy Bohnenkamp */
/* SAS Campus Drive */
/* Cary, NC 27513 */
/* */
/* */
/* If you prefer, you can send email to: sasbbu@sas.com */
/* Use this for subject field: */
/* Comments for Wendy Bohnenkamp */
/* */
/*-------------------------------------------------------------------*/
***Sample Code used in "SAS Graphics for Java" ;
Chapter 1.2 Code snipets
ADS2 connection example:
ADS3 example of data model and bar chart:
<%
barChartTableDataModel1.setCategoryVariable(
new com.sas.graphics.components.ClassificationVariable("COUNTRY"));
barChartTableDataModel1.setResponseVariable(
new com.sas.graphics.components.AnalysisVariable("AMOUNT"));
%>
***Sample Code used in Chapter 2 ;
Chapter 2.1.1 sasads:Bar
Chapter 2.1.2 sasads:Combination
Chapter 2.1.3 sasads:Pie
Chapter 2.1.4 sasads:Scatter
Chapter 2.1.5 sasads:SegmentedBar
Chapter 2.2.1 sas:BarChart
<%
barChartTableDataModel1.setCategoryVariable(
new com.sas.graphics.components.ClassificationVariable("COUNTRY"));
barChartTableDataModel1.setResponseVariable(
new com.sas.graphics.components.AnalysisVariable("AMOUNT"));
%>
Chapter 2.2.2 sas:BarLineChart
<%
barLineChartTableDataModel1.setCategoryVariable(
new com.sas.graphics.components.ClassificationVariable("TEACHER"));
barLineChartTableDataModel1.setLineResponseVariable(
new com.sas.graphics.components.AnalysisVariable("AGE",
com.sas.graphics.components.GraphConstants.STATISTIC_MEAN));
barLineChartTableDataModel1.setBarResponseVariable(
new com.sas.graphics.components.AnalysisVariable("HEART",
com.sas.graphics.components.GraphConstants.STATISTIC_MEAN));
%>
Chapter 2.2.3 sas:LineChart
<%
lineChartTableDataModel1.setCategoryVariable(
new com.sas.graphics.components.ClassificationVariable("COUNTRY"));
lineChartTableDataModel1.setResponseVariable(
new com.sas.graphics.components.AnalysisVariable("AMOUNT"));
%>
Chapter 2.2.4 sas:LinePlot
<%
linePlotTableDataModel1.setXVariable(
new com.sas.graphics.components.PlotVariable("IDNAME"));
linePlotTableDataModel1.setYVariable(
new com.sas.graphics.components.PlotVariable("POPDEN"));
%>
Chapter 2.2.5 sas:PieChart
<%
pieChartTableDataModel1.setCategoryVariable(
new com.sas.graphics.components.ClassificationVariable("COUNTRY"));
pieChartTableDataModel1.setResponseVariable(
new com.sas.graphics.components.AnalysisVariable("AMOUNT"));
%>
Chapter 2.2.6 sas:RadarChart
<%
radarChartTableDataModel1.setCategoryVariable(
new com.sas.graphics.components.ClassificationVariable("COUNTRY"));
radarChartTableDataModel1.setResponseVariable(
new com.sas.graphics.components.AnalysisVariable("AMOUNT"));
%>
Chapter 2.2.7 sas:ScatterPlot
<%
scatterPlotTableDataModel1.setXVariable(
new com.sas.graphics.components.PlotVariable("IDNAME"));
scatterPlotTableDataModel1.setYVariable(
new com.sas.graphics.components.PlotVariable("POPDEN"));
%>
***Selected Sample Code used in Chapter 2 ;
Chapter 2.3 Common Attributes - alignment (page 25)
<%@taglib uri="http://www.sas.com/taglib/sas" prefix="sas"%>
<%
jdbcProperties.setProperty("librefs", "samples 'c:/projects/BBU/data';" );
jdbcProperties.setProperty( "username", "sasdemo" );
jdbcProperties.setProperty( "password", "SAS1demo" );
%>
<%
barChartTDM1.setCategoryVariable(
new com.sas.graphics.components.ClassificationVariable("COUNTRY"));
barChartTDM1.setResponseVariable(
new com.sas.graphics.components.AnalysisVariable("AMOUNT"));
%>
***Selected Sample Code used in Chapter 3 ;
Chapter 3.3 LineChartModel - fillAreaEnabled (page 65)
<%@taglib uri="http://www.sas.com/taglib/sas" prefix="sas"%>
<%
jdbcProperties.setProperty("librefs", "samples 'c:/projects/BBU/data';" );
jdbcProperties.setProperty( "username", "sasdemo" );
jdbcProperties.setProperty( "password", "SAS1demo" );
%>
<%
com.sas.storage.jdbc.JDBCConnection jdbcConn =
(com.sas.storage.jdbc.JDBCConnection)
session.getAttribute("jdbcConn");
%>
<%
com.sas.storage.jdbc.JDBCToTableModelAdapter jdbcTMAGrains =
(com.sas.storage.jdbc.JDBCToTableModelAdapter)
session.getAttribute("jdbcTMAGrains");
%>
<%
lcTDMGrains2.setCategoryVariable(
new com.sas.graphics.components.ClassificationVariable("COUNTRY"));
lcTDMGrains2.setResponseVariable(
new com.sas.graphics.components.AnalysisVariable("AMOUNT"));
%>
***Selected Sample Code used in Chapter 4 ;
Chapter 4.4 Text Style Tags - various attributes (page 116)
<%@taglib uri="http://www.sas.com/taglib/sas" prefix="sas"%>
<%
jdbcProperties.setProperty("librefs", "samples 'c:/projects/BBU/data';" );
jdbcProperties.setProperty( "username", "sasdemo" );
jdbcProperties.setProperty( "password", "SAS1demo" );
%>
<%
com.sas.storage.jdbc.JDBCConnection jdbcConn =
(com.sas.storage.jdbc.JDBCConnection)
session.getAttribute("jdbcConn");
%>
<%
com.sas.storage.jdbc.JDBCToTableModelAdapter jdbcTMAPopData =
(com.sas.storage.jdbc.JDBCToTableModelAdapter)
session.getAttribute("jdbcTMAPopData");
%>
<%
lpTDMPopData.setXVariable(
new com.sas.graphics.components.PlotVariable("IDNAME"));
lpTDMPopData.setYVariable(
new com.sas.graphics.components.PlotVariable("POPDEN"));
%>
***Selected Sample Code used in Chapter 5 ;
Chapter 5.1 Fill Tags - fillType (page 127)
<%@taglib uri="http://www.sas.com/taglib/sas" prefix="sas"%>
<%
jdbcProperties.setProperty("librefs", "samples 'c:/projects/BBU/data';" );
jdbcProperties.setProperty( "username", "sasdemo" );
jdbcProperties.setProperty( "password", "SAS1demo" );
%>
<%
com.sas.storage.jdbc.JDBCConnection jdbcConn =
(com.sas.storage.jdbc.JDBCConnection)
session.getAttribute("jdbcConn");
%>
<%
com.sas.storage.jdbc.JDBCToTableModelAdapter jdbcTMAGrains =
(com.sas.storage.jdbc.JDBCToTableModelAdapter)
session.getAttribute("jdbcTMAGrains");
%>
<%
bcTDMGrains2.setCategoryVariable(
new com.sas.graphics.components.ClassificationVariable("COUNTRY"));
bcTDMGrains2.setResponseVariable(
new com.sas.graphics.components.AnalysisVariable("AMOUNT"));
%>
<% /*
[fillType="SolidColor|Gradient|Image|
ImageColorBlend|ImageGradientBlend"]
[gradientFill="LeftToRight|BottomToTop|
FrontToBack|DiagonalUp|DiagonalDown"]
*/ %>
***Sample Code used in Chapter 6 ;
Chapter 6.2 General JSP Structure
<%@taglib uri="http://www.sas.com/taglib/sasads" prefix="sasads"%>
<%@ page import = "com.sas.servlet.util.SocketListener" %>
<%@ page import = "com.sas.servlet.util.Util" %>
<%@ page import = "com.sas.rmi.Connection" %>
<%
SocketListener socket = new SocketListener();
int port = socket.setup();
String host = (java.net.InetAddress.getLocalHost()).getHostAddress();
String archivePath="../assets/graph/";
String libraryPath = "c:\\Projects\\BBU\\data";
socket.start();
%>
libname samples '<%=libraryPath%>';
filename sock SOCKET '<%=host%>:<%=port%>';
goptions reset=all device=java xpixels=600 ypixels=400;
ods listing close;
ODS HTML body=sock rs=none CODEBASE="<%=archivePath%>" ;
proc gchart data=samples.grains;
hbar country / sumvar=amount;
run;
quit;
ods html close;
<%
socket.write(out);
socket.close();
%>
***Sample Code used in Chapter 7 ;
Chapter 7.1 Types of Bar Charts
proc gchart data=samples.grains;
hbar country / sumvar=amount;
run;
proc gchart data=samples.grains;
hbar3d country / sumvar=amount;
run;
proc gchart data=samples.grains;
vbar country / sumvar=amount;
run;
Chapter 7.2 Types of Pie Charts
proc gchart data=samples.grains;
pie country / sumvar=amount;
run;
proc gchart data=samples.grains;
pie country / sumvar=amount;
run;
proc gchart data=samples.grains;
pie3d country / sumvar=amount;
run;
Chapter 7.2.2 Donut Charts
proc gchart data=samples.grains;
donut country / sumvar=amount;
run;
Chapter 7.2.3 Star Charts
proc gchart data=samples.grains;
star country / sumvar=amount;
run;
Chapter 7.3 Contour Plots
proc gcontour data=work.clay;
plot y*x=pct_clay / levels=10 to 90 by 5 ;
run;
Chapter 7.4 Types of Maps
proc gmap map=maps.us data=samples.rgnsites;
id state;
block sites;
run;
proc gmap map=maps.us data=samples.rgnsites;
id state;
choro sites;
run;
proc gmap map=maps.us data=samples.rgnsites;
id state;
prism sites;
run;
proc gmap map=maps.us data=samples.rgnsites;
id state;
surface sites;
run;
Chapter 7.5 Types of Plots
proc sql;
create table work.energyPrice as
select year as year, consumed as energy,
consumed*.03 as dollars, consumed*.03*125 as yen
from samples.energy1;
quit;
proc gplot data=work.energyPrice;
bubble dollars*year=energy;
run;
proc gplot data=work.energyPrice;
bubble dollars*year=energy;
bubble2 yen*year=energy;
run;
proc gplot data=work.energyPrice;
plot dollars*year;
run;
proc gplot data=work.energyPrice;
plot dollars*year;
plot2 yen*year;
run;
Chapter 7.6 Three-Dimensional Graphs
proc g3d data=samples.giris;
scatter petallen*petalwid=sepallen;
run;
proc g3d data=samples.hat;
plot y*x=z;
run;
***Selected Sample Code used in Chapter 8 ;
Chapter 8.1 ODS Parameters - GRADIENTBACKGROUND (page 176)
<%@taglib uri="http://www.sas.com/taglib/sasads" prefix="sasads"%>
<%@ page import = "com.sas.servlet.util.SocketListener" %>
<%@ page import = "com.sas.servlet.util.Util" %>
<%@ page import = "com.sas.rmi.Connection" %>
<%
SocketListener socket = new SocketListener();
int port = socket.setup();
String host = (java.net.InetAddress.getLocalHost()).getHostAddress();
String archivePath="../assets/graph/";
String libraryPath = "c:\\Projects\\BBU\\data";
socket.start();
%>
libname samples '<%=libraryPath%>';
filename sock SOCKET '<%=host%>:<%=port%>';
goptions reset=all device=java xpixels=600 ypixels=400;
ods listing;
ods html close;
ODS HTML body=sock rs=none CODEBASE="<%=archivePath%>"
parameters=("gradientbackground"="vertical"
"gradientstartcolor"="red"
"gradientendcolor"="yellow");
proc gmap map=maps.us data=samples.rgnsites;
id state;
prism sites;
run;
quit;
ods html close;
ods listing;
<%
socket.write(out);
socket.close();
%>
***Selected Sample Code used in Chapter 9 ;
Chapter 9.2 GOPTIONS - FTITLE (page 215)
<%@taglib uri="http://www.sas.com/taglib/sasads" prefix="sasads"%>
<%@ page import = "com.sas.servlet.util.SocketListener" %>
<%@ page import = "com.sas.servlet.util.Util" %>
<%@ page import = "com.sas.rmi.Connection" %>
<%
SocketListener socket = new SocketListener();
int port = socket.setup();
String host = (java.net.InetAddress.getLocalHost()).getHostAddress();
String archivePath="../assets/graph/";
String libraryPath = "c:\\Projects\\BBU\\data";
socket.start();
%>
libname samples '<%=libraryPath%>';
filename sock SOCKET '<%=host%>:<%=port%>';
goptions reset=all device=java xpixels=600 ypixels=400
ftitle=courier;
ods listing;
ods html close;
ODS HTML body=sock rs=none CODEBASE="<%=archivePath%>";
ODS USEGOPT;
title1 "Proc GChart - Courier Title";
proc gchart data=samples.grains;
hbar3d country / sumvar=amount;
run;
quit;
ods html close;
ods listing;
<%
socket.write(out);
socket.close();
%>
***Selected Sample Code used in Chapter 10 ;
Chapter 10.1 PROC GCHART - AXIS/RAXIS (page 244)
<%@taglib uri="http://www.sas.com/taglib/sasads" prefix="sasads"%>
<%@ page import = "com.sas.servlet.util.SocketListener" %>
<%@ page import = "com.sas.servlet.util.Util" %>
<%@ page import = "com.sas.rmi.Connection" %>
<%
SocketListener socket = new SocketListener();
int port = socket.setup();
String host = (java.net.InetAddress.getLocalHost()).getHostAddress();
String archivePath="../../assets/graph/";
String libraryPath = "c:\\Projects\\BBU\\data";
socket.start();
%>
libname samples '<%=libraryPath%>';
filename sock SOCKET '<%=host%>:<%=port%>';
goptions reset=all device=java xpixels=600 ypixels=400;
ods listing close;
ODS HTML body=sock rs=none CODEBASE="<%=archivePath%>";
axis1 color=red;
proc gchart data=samples.grains;
vbar3d country /
sumvar=amount
axis=axis1;
run;
quit;
ods html close;
<%
socket.write(out);
socket.close();
%>
***Programs used in "SAS Graphics for Java" ;
Chapter 11.1 Report 1: Using SAS AppDev Studio 3 Tags
<%@taglib uri="http://www.sas.com/taglib/sas" prefix="sas"%>
<%
java.util.Properties jdbcProperties = new java.util.Properties();
jdbcProperties.setProperty("librefs", "samples 'c:/projects/BBU/data';" );
jdbcProperties.setProperty( "username", "sasdemo" );
jdbcProperties.setProperty( "password", "SAS1demo" );
session.setAttribute( "jdbcProperties", jdbcProperties );
%>
<%
report1_TableDataModel.setCategoryVariable(
new com.sas.graphics.components.ClassificationVariable("ENGYTYPE"));
report1_TableDataModel.setResponseVariable(
new com.sas.graphics.components.AnalysisVariable("AMOUNT"));
report1_TableDataModel.setSubgroupVariable(
new com.sas.graphics.components.ClassificationVariable("YEAR"));
%>
Energy Production 1985- 1988
***Programs used in "SAS Graphics for Java" ;
Chapter 11.2 Report 2: Using ODS
<%@taglib uri="http://www.sas.com/taglib/sasads" prefix="sasads"%>
<%@ page import = "com.sas.servlet.util.SocketListener" %>
<%@ page import = "com.sas.servlet.util.Util" %>
<%@ page import = "com.sas.rmi.Connection" %>
<%
SocketListener socket = new SocketListener();
int port = socket.setup();
String host = (java.net.InetAddress.getLocalHost()).getHostAddress();
String archivePath="../../assets/graph/";
String libraryPath = "c:\\Projects\\BBU\\data";
socket.start();
%>
libname samples '<%=libraryPath%>';
filename sock SOCKET '<%=host%>:<%=port%>';
goptions reset=all device=java xpixels=600 ypixels=400;
ods listing close;
ODS HTML body=sock rs=none CODEBASE="<%=archivePath%>"
parameters=("colorscheme"="fall") style=beige;
legend1 label=('Energy Type');
title1 'Energy Production 1985 - 1988';
proc gchart data=samples.eprdcon2;
pie engytype /
sumvar=amount
detail=year
legend=legend1
;
run;
ods html close;
<%
socket.write(out);
socket.close();
%>
**WORK Data Sets" ;
Appendix A Work Data Sets
work.clay
data work.clay;
set samples.clay;
where x ge -10 and x le -4 and y ge -10 and y le 2;
run;
proc sql;
create table work.energyPrice as
select year as year, consumed as energy, consumed*.03 as dollars,
consumed*.03*125 as yen
from samples.energy1;
quit;