// FillAreas:


// When the specification on the data model generates multiple plot lines,
// the areas between the lines can be filled by calling the
// LineChartModel's setFillAreaEnabled() method with the argument value
// true. Optionally, you can define a fill for the areas and set the
// fill on the DataElementStyles. This sample uses the SubgroupVariable
// role to generate multiple plot lines.

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

     // Create a LineChart and a data source 
        LineChart lineChart=new LineChart();
        SampleData dataTable=new SampleData();

     // Get the plot's graph model and enable filled areas
        LineChartModel graphModel=lineChart.getGraphModel();
        graphModel.setFillAreaEnabled(true);

     // Create transparent fills for the filled areas
        FillStyle[] transparencies=new FillStyle[] {
          new FillStyle(new Color(204,0,102,100) ),    // red transparency
          new FillStyle(new Color(102,153,102,100) ),  // green transparency
          new FillStyle(new Color(51,102,255,100) ) }; // blue transparency

     // Set the fills on the plot areas
        graphModel.getDataElementStyles().setFillStyles(transparencies);

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

     // Assign the SubgroupVariable role so there are multiple plots
        dataModel.setSubgroupVariable(
                  new ClassificationVariable("City"));

     // Assign the Category and Response variable roles
        dataModel.setCategoryVariable(
                  new ClassificationVariable("Month"));
        dataModel.setResponseVariable(
                  new AnalysisVariable("Temp"));

     // Assign the data model to the LineChart
        lineChart.setDataModel(dataModel);

     // Set a graph title
        lineChart.getTitle1().setText(
                  "Monthly Temperatures");

        add(lineChart, BorderLayout.CENTER);
      }
  // Create the data source
     static private class SampleData extends DefaultTableModel {
       private static Class  columnClass[]={
                   Double.class, Double.class, String.class};
       private static String columnNames[]={
                  "Month","Temp","City"};
         public SampleData() {
	   super();
           Object data[][] = {
             {new Double(1),  new Double(40.5),   "Raleigh" }, 
             {new Double(1),  new Double(12.2),   "Minn"    },
             {new Double(1),  new Double(52.1),   "Phoenix" }, 
             {new Double(2),  new Double(42.2),   "Raleigh" }, 
             {new Double(2),  new Double(16.5),   "Minn"    }, 
             {new Double(2),  new Double(55.1),   "Phoenix" }, 
             {new Double(3),  new Double(49.2),   "Raleigh" }, 
             {new Double(3),  new Double(28.3),   "Minn"    }, 
             {new Double(3),  new Double(59.7),   "Phoenix" }, 
             {new Double(4),  new Double(59.5),   "Raleigh" }, 
             {new Double(4),  new Double(45.1),   "Minn"    }, 
             {new Double(4),  new Double(67.7),   "Phoenix" }, 
             {new Double(5),  new Double(67.4),   "Raleigh" }, 
             {new Double(5),  new Double(57.1),   "Minn"    }, 
             {new Double(5),  new Double(76.3),   "Phoenix" }, 
             {new Double(6),  new Double(74.4),   "Raleigh" }, 
             {new Double(6),  new Double(66.9),   "Minn"    }, 
             {new Double(6),  new Double(84.6),   "Phoenix" }, 
             {new Double(7),  new Double(77.5),   "Raleigh" }, 
             {new Double(7),  new Double(71.9),   "Minn"    }, 
             {new Double(7),  new Double(91.2),   "Phoenix" }, 
             {new Double(8),  new Double(76.5),   "Raleigh" }, 
             {new Double(8),  new Double(70.2),   "Minn"    }, 
             {new Double(8),  new Double(89.1),   "Phoenix" }, 
             {new Double(9),  new Double(70.6),   "Raleigh" }, 
             {new Double(9),  new Double(60.0),   "Minn"    }, 
             {new Double(9),  new Double(83.8),   "Phoenix" }, 
             {new Double(10), new Double(60.2),   "Raleigh" }, 
             {new Double(10), new Double(50.0),   "Minn"    }, 
             {new Double(10), new Double(72.2),   "Phoenix" }, 
             {new Double(11), new Double(50.0),   "Raleigh" }, 
             {new Double(11), new Double(32.4),   "Minn"    }, 
             {new Double(11), new Double(59.8),   "Phoenix" }, 
             {new Double(12), new Double(41.2),   "Raleigh" }, 
             {new Double(12), new Double(18.6),   "Minn"    }, 
             {new Double(12), new Double(52.5),   "Phoenix" }
           };
           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());
          FillAreas  bipGraphSample = new FillAreas ();

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