// Basic Requirements:
// Basic requirements for creating an AreaBar chart:
// 1) Create an AreaBarChart instance and a data source
// 2) Create a data model and attach the data source to it
// 3) Assign the Category, Height, and Width variable roles
// to appropriate variables
// 4) Assign the data model to the AreaBarChart
import com.sas.graphics.components.areabarchart.AreaBarChart;
import com.sas.graphics.components.areabarchart.AreaBarChartTableDataModel;
import com.sas.graphics.components.AnalysisVariable;
import com.sas.graphics.components.ClassificationVariable;
import com.sas.graphics.components.GraphConstants;
import javax.swing.table.DefaultTableModel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class BasicRequirements extends JPanel {
private BasicRequirements theApp;
public BasicRequirements () {
setLayout(new BorderLayout());
// 1) Create an AreaBarChart instance and a data source
AreaBarChart areaBarChart=new AreaBarChart();
SampleData dataTable=new SampleData();
// 2) Create a data model and attach the data source
AreaBarChartTableDataModel dataModel=
new AreaBarChartTableDataModel();
dataModel.setModel(dataTable);
// 3) Assign variable roles to appropriate variables
dataModel.setCategoryVariable(
new ClassificationVariable("Group"));
dataModel.setHeightVariable(
new AnalysisVariable("Height"));
dataModel.setWidthVariable(
new AnalysisVariable("Weight"));
// 4) Assign the data model to the AreaBarChart
areaBarChart.setDataModel(dataModel);
// Set a graph title
areaBarChart.getTitle1().setText("Basic AreaBarChart");
add(areaBarChart, BorderLayout.CENTER);
}
// Create the data source
static private class SampleData extends DefaultTableModel {
private static Class columnClass[]={String.class, String.class,
Double.class, Double.class};
private static String columnNames[]={"Group","Age","Height","Weight"};
public SampleData() {
super();
Object data[][] = {
{ "Group 1", new String("y"+13), new Double(56.5), new Double(84) },
{ "Group 1", new String("y"+12), new Double(50.5), new Double(98) },
{ "Group 1", new String("y"+11), new Double(49), new Double(50.5) },
{ "Group 1", new String("y"+12), new Double(46.3), new Double(77) },
{ "Group 1", new String("y"+12), new Double(53), new Double(96.5) },
{ "Group 2", new String("y"+14), new Double(62.8), new Double(102.5) },
{ "Group 2", new String("y"+16), new Double(70), new Double(140) },
{ "Group 2", new String("y"+14), new Double(59.5), new Double(102) },
{ "Group 3", new String("y"+15), new Double(62), new Double(112.5) },
{ "Group 2", new String("y"+14), new Double(64.3), new Double(90) },
{ "Group 3", new String("y"+15), new Double(66.5), new Double(112) },
{ "Group 1", new String("y"+12), new Double(59), new Double(99.5) },
{ "Group 1", new String("y"+13), new Double(62.5), new Double(84) },
{ "Group 1", new String("y"+12), new Double(64.8), new Double(128) },
{ "Group 1", new String("y"+12), new Double(57.3), new Double(83) },
{ "Group 1", new String("y"+11), new Double(57.5), new Double(85) },
{ "Group 3", new String("y"+15), new Double(77), new Double(133) },
{ "Group 3", new String("y"+15), new Double(66.5), new Double(112) },
{ "Group 2", new String("y"+14), new Double(63.5), new Double(102.5) },
{ "Group 3", new String("y"+16), new Double(72), new Double(150) }
};
setDataVector(data, columnNames);
}
public Class getColumnClass(int column) {
return columnClass[column];
}
}
public static void main(String[] args) {
JFrame frame = new JFrame("BIP Graph Sample");
Container container = frame.getContentPane();
container.setLayout(new BorderLayout());
container.setBackground(Color.white);
JPanel bipPanel = new JPanel();
bipPanel.setLayout(new BorderLayout());
BasicRequirements bipGraphSample = new BasicRequirements ();
bipPanel.add(bipGraphSample, BorderLayout.CENTER);
container.add(bipPanel, BorderLayout.CENTER);
frame.setSize(600,450);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
} );
frame.pack();
frame.setVisible(true);
}
}