// MultipleResponseVars:


// To plot mutliple Response variables by the same Category variable, add the 
// Response variables to a AnalysisVariableList, and then assign the Response role
// to that list rather than to an individual variable.
//
// Optionally, you can modify the Response axis and specify labels.
// This sample also disables markers and enables plot interpolation.

   import com.sas.graphics.components.AnalysisVariable;
   import com.sas.graphics.components.AnalysisVariableList;
   import com.sas.graphics.components.GraphConstants;
   import com.sas.graphics.components.ClassificationVariable;
   import com.sas.graphics.components.linechart.LineChart;
   import com.sas.graphics.components.linechart.LineChartModel;
   import com.sas.graphics.components.linechart.LineChartTableDataModel;
   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 MultipleResponseVars extends JPanel  {
     private MultipleResponseVars  theApp;
     public MultipleResponseVars () {
        setLayout(new BorderLayout());

     // Create a data model and attach the data (defined below)
        LineChartTableDataModel dataModel = null;
        dataModel=new LineChartTableDataModel(new TestData());

     // Create a line chart and get its model
        LineChart lineChart=new LineChart(dataModel);
        LineChartModel graphModel=lineChart.getGraphModel();

     // Define a Category variable
        ClassificationVariable oneCategory=new ClassificationVariable("x1");

     // Define multiple Response variables
        AnalysisVariableList multiResponse=new AnalysisVariableList(
                  new AnalysisVariable[] {
                      new AnalysisVariable("y1"),
                      new AnalysisVariable("y2")
                  } );

     // Assign the Category and Response variable roles
        dataModel.setCategoryVariable(oneCategory);
        dataModel.setResponseVariable(multiResponse);

     // Modify the Response axis and specify axis and legend labels
	graphModel.getResponseAxisModel().setLabel("Multiple Response Columns");
        graphModel.getResponseAxisModel().getMinorTickStyle().getLineStyle().setVisibilityPolicy(GraphConstants.FALSE);

     // Set a graph title
        lineChart.getTitle1().setText(
                 "Multiple Response Variables");

        add(lineChart, BorderLayout.CENTER);
      }
     static private class TestData extends DefaultTableModel {
       private static Class  columnClass[]={ Double.class
                                            , Double.class
                                            , Double.class
                                            , Double.class
                                            , Double.class
                                            , Double.class
                                            };
                                            
        private static String columnNames[]={ "x1"
                                            , "x2"
                                            , "x3"
                                            , "y1"
                                            , "y2"
                                            , "y3"
                                            };

	    public TestData()
	    {
	        super();
            Object data[][]={ 
                              {new Double( 10),new Double( 20), new Double( 30), new Double(  3),new Double(  5), new Double(  25)}
                            , {new Double( 20),new Double( 30), new Double( 40), new Double(  6),new Double(  10), new Double(  30)}
                            , {new Double( 30),new Double( 40), new Double( 50), new Double(  9),new Double(  15), new Double(  35)}
                            , {new Double( 40),new Double( 50), new Double( 60), new Double(  12),new Double(  20), new Double(  40)}
                            , {new Double( 50),new Double( 60), new Double( 70), new Double(  15),new Double(  25), new Double(  50)}
                            , {new Double( 70),new Double( 80), new Double( 90), new Double(  18),new Double( 20), new Double(  55)}
                            , {new Double( 80),new Double( 90), new Double( 100), new Double(  21),new Double(  15), new Double(  60)}
                            , {new Double( 90),new Double( 100), new Double( 110), new Double(  24),new Double(  10), new Double(  65)}
                            , {new Double( 100),new Double( 110), new Double( 120), new Double(  27),new Double(  5), new Double(  70)}
                            };
            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());
          MultipleResponseVars  bipGraphSample = new MultipleResponseVars ();

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