// BubblePlot:
// To generate a bubble plot whose marker size is
// determined by the values of a variable, assign
// the Size role to that variable.
import com.sas.graphics.components.scatterplot.ScatterPlot;
import com.sas.graphics.components.scatterplot.ScatterPlotTableDataModel;
import com.sas.graphics.components.ClassificationVariable;
import com.sas.graphics.components.PlotVariable;
import com.sas.graphics.components.Variable;
import com.sas.graphics.components.GraphConstants;
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;
import javax.swing.table.DefaultTableModel;
public class BubblePlot extends JPanel {
private BubblePlot theApp;
public BubblePlot () {
setLayout(new BorderLayout());
// Create a ScatterPlot and a data source
ScatterPlot scatterPlot=new ScatterPlot();
SampleData dataTable=new SampleData();
// Create a data model and attach the data source
ScatterPlotTableDataModel dataModel=
new ScatterPlotTableDataModel();
dataModel.setModel(dataTable);
// Assign the X and Y variable roles
dataModel.setXVariable(
new PlotVariable("Region"));
dataModel.setYVariable(
new PlotVariable("Revenue", "dollar7",null,null));
dataModel.setSizeVariable(
new Variable("UnitSales"));
// Assign the data model to the ScatterPlot
scatterPlot.setDataModel(dataModel);
// Set a graph title
scatterPlot.getTitle1().setText(
"Bubble Plot");
add(scatterPlot, BorderLayout.CENTER);
}
// Create the data source
static private class SampleData extends DefaultTableModel {
private static Class columnClass[]={
String.class, Double.class, Double.class};
private static String columnNames[]={
"Region","Revenue","UnitSales"};
public SampleData() {
super();
Object data[][] = {
{"North", new Double(27308), new Double(73273) },
{"East.", new Double(29844), new Double(64192) },
{"South", new Double(22920), new Double(89382) },
{"West" , new Double(18444), new Double(54833) },
};
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());
BubblePlot bipGraphSample = new BubblePlot ();
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.setVisible(true);
}
}