// SpecifyStatistic:


// To specify a statistic, use the AnalysisVariable constructor

   import com.sas.graphics.components.radarchart.RadarChart;
   import com.sas.graphics.components.radarchart.RadarChartTableDataModel;
   import com.sas.graphics.components.AnalysisVariable;
   import com.sas.graphics.components.ClassificationVariable;
   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 SpecifyStatistic extends JPanel  {
     private SpecifyStatistic  theApp;
     public SpecifyStatistic () {
        setLayout(new BorderLayout());

     // Create a RadarChart and a data source 
        RadarChart radarChart=new RadarChart();
        SampleData dataTable=new SampleData();

     // Create a data model and attach the data source
        RadarChartTableDataModel dataModel=
                  new RadarChartTableDataModel();
        dataModel.setModel(dataTable);

     // Create an AnalysisVariable and specify statistic
        AnalysisVariable response=new AnalysisVariable(
          "Count"                         // column for Response role
          ,GraphConstants.STATISTIC_MEAN  // statistic to calculate
        );

     // Assign the Category and Response variable roles
         dataModel.setCategoryVariable(
                  new ClassificationVariable("Cause"));
         dataModel.setResponseVariable(response);

     // Assign the data model to the BarChart
        radarChart.setDataModel(dataModel);

     // Set a graph title
        radarChart.getTitle1().setText("Causes of Failure");
        radarChart.getTitle2().setText("Mean Values");

        add(radarChart, BorderLayout.CENTER);
      }
   // Create the data source
      static private class SampleData extends DefaultTableModel {
        private static Class  columnClass[]={String.class, String.class,
                                             String.class, Double.class};
        private static String columnNames[]={"Process","Day","Cause","Count"};
          public SampleData() {
	    super();
            Object data[][] = {
              {"Process A", "March 1", "Contamination",  new Double(15)}, 
              {"Process A", "March 1", "Corrosion",      new Double(2) }, 
              {"Process A", "March 1", "Doping",         new Double(1) },
              {"Process A", "March 1", "Metallization",  new Double(2) }, 
              {"Process A", "March 1", "Miscellaneous",  new Double(3) },
              {"Process A", "March 1", "Oxide Defect",   new Double(8) }, 
              {"Process A", "March 1", "Silicon Defect", new Double(1) }, 
              {"Process A", "March 2", "Contamination",  new Double(16)},
              {"Process A", "March 2", "Corrosion",      new Double(3) },
              {"Process A", "March 2", "Doping",         new Double(1) }, 
              {"Process A", "March 2", "Metallization",  new Double(3) },
              {"Process A", "March 2", "Miscellaneous",  new Double(1) }, 
              {"Process A", "March 2", "Oxide Defect",   new Double(9) },
              {"Process A", "March 2", "Silicon Defect", new Double(2) }, 
              {"Process A", "March 3", "Contamination",  new Double(20)},
              {"Process A", "March 3", "Corrosion",      new Double(1) }, 
              {"Process A", "March 3", "Doping",         new Double(1) }, 
              {"Process A", "March 3", "Metallization",  new Double(0) },
              {"Process A", "March 3", "Miscellaneous",  new Double(3) },
              {"Process A", "March 3", "Oxide Defect",   new Double(7) },
              {"Process A", "March 3", "Silicon Defect", new Double(2) }, 
              {"Process A", "March 4", "Contamination",  new Double(12)}, 
              {"Process A", "March 4", "Corrosion",      new Double(1) }, 
              {"Process A", "March 4", "Doping",         new Double(1) }, 
              {"Process A", "March 4", "Metallization",  new Double(0) },
              {"Process A", "March 4", "Miscellaneous",  new Double(0) },
              {"Process A", "March 4", "Oxide Defect",  new Double(10)},
              {"Process A", "March 4", "Silicon Defect", new Double(1) }, 
              {"Process A", "March 5", "Contamination",  new Double(23)},
              {"Process A", "March 5", "Corrosion",      new Double(1) }, 
              {"Process A", "March 5", "Doping",         new Double(1) }, 
              {"Process A", "March 5", "Metallization",  new Double(0) },
              {"Process A", "March 5", "Miscellaneous",  new Double(1) }, 
              {"Process A", "March 5", "Oxide Defect",   new Double(8) }, 
              {"Process A", "March 5", "Silicon Defect", new Double(2) }, 
              {"Process B", "March 1", "Contamination", new Double(8) }, 
              {"Process B", "March 1", "Corrosion",      new Double(2) }, 
              {"Process B", "March 1", "Doping",         new Double(1) }, 
              {"Process B", "March 1", "Metallization",  new Double(4) },
              {"Process B", "March 1", "Miscellaneous",  new Double(2) }, 
              {"Process B", "March 1", "Oxide Defect",  new Double(10)},
              {"Process B", "March 1", "Silicon Defect", new Double(3) },
              {"Process B", "March 2", "Contamination", new Double(9) },
              {"Process B", "March 2", "Corrosion",      new Double(0) },
              {"Process B", "March 2", "Doping",         new Double(1) }, 
              {"Process B", "March 2", "Metallization",  new Double(2) }, 
              {"Process B", "March 2", "Miscellaneous",  new Double(4) },
              {"Process B", "March 2", "Oxide Defect",   new Double(9) },
              {"Process B", "March 2", "Silicon Defect", new Double(2) }, 
              {"Process B", "March 3", "Contamination", new Double(4) },
              {"Process B", "March 3", "Corrosion",      new Double(1) }, 
              {"Process B", "March 3", "Doping",         new Double(1) }, 
              {"Process B", "March 3", "Metallization",  new Double(0) },
              {"Process B", "March 3", "Miscellaneous",  new Double(0) },
              {"Process B", "March 3", "Oxide Defect",  new Double(10)},
              {"Process B", "March 3", "Silicon Defect", new Double(1) }, 
              {"Process B", "March 4", "Contamination", new Double(2) }, 
              {"Process B", "March 4", "Corrosion",      new Double(2) }, 
              {"Process B", "March 4", "Doping",         new Double(1) }, 
              {"Process B", "March 4", "Metallization",  new Double(0) },
              {"Process B", "March 4", "Miscellaneous",  new Double(3) },
              {"Process B", "March 4", "Oxide Defect",   new Double(7) },
              {"Process B", "March 4", "Silicon Defect", new Double(1) }, 
              {"Process B", "March 5", "Contamination", new Double(1) }, 
              {"Process B", "March 5", "Corrosion",      new Double(3) },
              {"Process B", "March 5", "Doping",         new Double(1) }, 
              {"Process B", "March 5", "Metallization",  new Double(0) },
              {"Process B", "March 5", "Miscellaneous",  new Double(1) }, 
              {"Process B", "March 5", "Oxide Defect",   new Double(8) }, 
              {"Process B", "March 5", "Silicon Defect", new Double(2) } 
            };
            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());
          SpecifyStatistic  bipGraphSample = new SpecifyStatistic ();

          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);
      }
   }