// ChangeMarkers:
// To change the marker symbols in the risk map:
// 1) Define a MarkerStyle for the plot markers
// 2) Use the RiskMapPlotModel's data element styles to call the
// setMarkerStyles() method
import com.sas.graphics.components.MarkerStyle;
import com.sas.graphics.components.PlotVariable;
import com.sas.graphics.components.SegmentedRangeModel;
import com.sas.graphics.components.riskmapplot.RiskMapPlot;
import com.sas.graphics.components.riskmapplot.RiskMapPlotModel;
import com.sas.graphics.components.riskmapplot.RiskMapPlotTableDataModel;
import com.sas.graphics.components.riskmapplot.SimpleRiskMap;
import javax.swing.table.DefaultTableModel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.Container;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class ChangeMarkers extends JPanel {
private ChangeMarkers theApp;
public ChangeMarkers () {
setLayout(new BorderLayout());
Data dataTable = new Data(); // defined below
RiskMapPlotTableDataModel dataModel=
new RiskMapPlotTableDataModel(dataTable);
dataModel.setXVariable(new PlotVariable("Systolic Blood Pressure"));
dataModel.setYVariable(new PlotVariable("Blood Sugar"));
SegmentedRangeModel xRange = SegmentedRangeModel.
newSegmentedRangeModel(new double[]{0, 120, 135, 160, 200});
SegmentedRangeModel yRange = SegmentedRangeModel.
newSegmentedRangeModel(new double[]{0, 100, 120, 160, 400});
SimpleRiskMap simpleRiskMap = new SimpleRiskMap(xRange, yRange,
new Color[]{Color.GREEN,Color.YELLOW, Color.ORANGE, Color.RED},
SimpleRiskMap.TYPE_BLOCK);
RiskMapPlot riskMapPlot = new RiskMapPlot(dataModel);
RiskMapPlotModel graphModel=riskMapPlot.getGraphModel();
graphModel.setRiskMap(simpleRiskMap);
// 1) Define a MarkerStyle for the plot markers
MarkerStyle[] markerStyle=new MarkerStyle[] {
new MarkerStyle(MarkerStyle.SYMBOL_SQUARE_FILLED)};
// 2) Use the RiskMapPlotModel's data element styles to call the
// setMarkerStyles() method
graphModel.getDataElementStyles().setMarkerStyles(markerStyle);
add(riskMapPlot, BorderLayout.CENTER);
}
private static class Data extends DefaultTableModel
{
private Class columnClass[] = {Double.class, Double.class};
private String columnNames[] = {"Blood Sugar", "Systolic Blood Pressure"};
private Object data[][] = {
{new Double(140), new Double(95)},
{new Double(205), new Double(145)},
{new Double(175), new Double(152)},
{new Double(300), new Double(142)},
{new Double(230), new Double(115)},
{new Double(125), new Double(125)}
};
public Data()
{
super();
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());
ChangeMarkers bipGraphSample = new ChangeMarkers();
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);
}
}