// Error Values:
// To use error values in a chart, specify multiple columns on the
// AnalysisVariable(s) used in the plot. The first specified column
// is used for the variable's assigned roll, the second for the
// high errors, and the third for the low errors.
import java.awt.BorderLayout;
import javax.swing.JApplet;
import javax.swing.table.DefaultTableModel;
import com.sas.graphics.components.AnalysisVariable;
import com.sas.graphics.components.ClassificationVariable;
import com.sas.graphics.components.barchart.BarChart;
import com.sas.graphics.components.barchart.BarChartModel;
import com.sas.graphics.components.barchart.BarChartTableDataModel;
import com.sas.graphics.components.GraphConstants;
import com.sas.graphics.components.NoteModel;
public class ErrorValues extends JApplet {
public void init() {
// Create a BarChart and a data model (data defined below)
BarChartTableDataModel dataModel = null;
dataModel = new BarChartTableDataModel(new TestData());
// Create two AnalysisVariables with error values
AnalysisVariable errResponse=new AnalysisVariable(
"Var2" // column for Response role
, null // format
, null // informat
, "Var2 label" // label
, GraphConstants.STATISTIC_SUM // statistic
, "Var3" // highColumnName
, "Var3 label" // highLabel
, "Var4" // lowColumnName
, "Var4 label" // lowLabel
);
// Assign variable roles
dataModel.setResponseVariable(errResponse);
dataModel.setCategoryVariable(new ClassificationVariable("Var1"));
// Create a bar chart and get its model
BarChart barChart = new BarChart(dataModel);
BarChartModel graphModel = barChart.getGraphModel();
// Set a graph title
NoteModel title=barChart.getTitle1();
title.setText(
"Use Error Values");
// Add the BarChart to the Applet's content pane
getContentPane().add(barChart,BorderLayout.CENTER);
}
// Create the data source
static private class TestData extends DefaultTableModel {
private static Class columnClass[]={ String.class
, Double.class
, Double.class
, Double.class
};
private static String columnNames[]={ "Var1"
, "Var2"
, "Var3"
, "Var4"
};
public TestData() {
super();
Object data[][]={
{"2001", new Double( 52), new Double( 13), new Double( 15)}
, {"2001", new Double( 52), new Double( 5), new Double( 25)}
, {"2001", new Double( 38), new Double( 24), new Double( 12)}
, {"2001", new Double( 77), new Double( 18), new Double( 11)}
, {"2001", new Double( 34), new Double( 26), new Double( 19)}
, {"2001", new Double( 92), new Double( 12), new Double( 33)}
, {"2001", new Double( 60), new Double( 31), new Double( 17)}
, {"2001", new Double( 29), new Double( 17), new Double( 28)}
, {"2002", new Double( 35), new Double( 25), new Double( 25)}
, {"2002", new Double( 10), new Double( 10), new Double( 10)}
, {"2002", new Double( 15), new Double( 15), new Double( 15)}
, {"2002", new Double( 20), new Double( 20), new Double( 20)}
, {"2002", new Double( 25), new Double( 25), new Double( 25)}
, {"2002", new Double( 30), new Double( 30), new Double( 30)}
, {"2002", new Double( 35), new Double( 35), new Double( 35)}
, {"2003", new Double( 55), new Double(-15), new Double(-15)}
, {"2003", new Double( 30), new Double( 10), new Double( 10)}
, {"2003", new Double( 15), new Double( 15), new Double( 15)}
, {"2003", new Double( 0), new Double( 20), new Double( 20)}
, {"2003", new Double( 15), new Double( 25), new Double( 25)}
, {"2003", new Double( 30), new Double(-30), new Double( 30)}
, {"2003", new Double( 35), new Double( 35), new Double( 35)}
};
setDataVector(data, columnNames);
}
public Class getColumnClass(int column) {
return columnClass[column];
}
}
}