// ChangeAxis:


// A graph's display properties (including axis characteristics)
// are general properties that are defined in the graph's model.
// Thus, to change a WaterfallChart's axis characteristics,
//    1) Create an AxisModel and any other objects needed to define
//       axis characteristics (line style, tick intervals, ...)
//    2) Use the WaterfallChart to set the axis definitions on the chart
// This example creates a StrokeLineStyle to define a
// 3pt solid red line for both the Category and Response axes.
// It creates an AxisModel to suppress the axis label and define
// a line style and tick characteristics for the Response axis.

   import com.sas.graphics.components.waterfallchart.WaterfallChart;
   import com.sas.graphics.components.waterfallchart.WaterfallChartTableDataModel;
   import com.sas.graphics.components.AnalysisVariable;
   import com.sas.graphics.components.ClassificationVariable;
   import com.sas.graphics.components.AxisModel;
   import com.sas.graphics.components.GraphConstants;
   import com.sas.graphics.components.StrokeLineStyle;
   import com.sas.measures.BaseLength;
   import javax.swing.table.DefaultTableModel;
   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;

   public class ChangeAxis extends JPanel  {
     private ChangeAxis  theApp;
     public ChangeAxis () {
        setLayout(new BorderLayout());

     // Create a WaterfallChart and a data source 
        WaterfallChart waterfallChart=new WaterfallChart();
        SampleData dataTable=new SampleData();

     // 1) Create the objects needed to define axis characteristics.
     // A StrokeLineStyle is needed to define line characteristics
     // for both axes
        StrokeLineStyle lineStyle=new StrokeLineStyle(
          StrokeLineStyle.SASGRAPH_LINE01,
          Color.red,
          new BaseLength(3, "pt"),
          GraphConstants.TRUE);

     // An AxisModel is needed to suppress the axis label and define
     // a line style and tick characteristics for the Response axis
        AxisModel rAxis = new AxisModel();
        rAxis.setLabel("");
        rAxis.setAxisLineStyle(lineStyle);
        rAxis.setContinuousMajorTickPositionPolicy(
          GraphConstants.TICK_POSITION_INTERVAL);
        rAxis.setContinuousMajorTickInterval(200);
        rAxis.getMinorTickStyle().getLineStyle()
         .setVisibilityPolicy(GraphConstants.FALSE);

     // 2) Use the WaterfallChart to set the axis definitions on the chart

     // Set the line color on the Category axis
        waterfallChart.getGraphModel().getCategoryAxisModel()
         .setAxisLineStyle(lineStyle);

     // Set the AxisModel on the Response axis
        waterfallChart.getGraphModel().setResponseAxisModel(rAxis);

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

      // Assign the variable roles and sort category values in descending order
         dataModel.setCategoryVariable(
                  new ClassificationVariable("Id", GraphConstants.SORT_DESCENDING));

     // Assign the Response variable role and apply the NLMNLUSD format so
     // that Transaction amounts in the output are displayed in an
     // internationalized representation of US dollars.
        dataModel.setResponseVariable(
                  new AnalysisVariable("Transaction", "nlmnlusd"));

     // Call the data model's setCategorySortVariable() method
     // to sort bars according to the values of the response variable
        dataModel.setCategorySortVariable(dataModel.getResponseVariable());

     // Assign the data model to the WaterfallChart
        waterfallChart.setDataModel(dataModel);

     // Set a graph title
        waterfallChart.getTitle1().setText("BIP Waterfall Chart");
        add(waterfallChart, BorderLayout.CENTER);
     }
     // Create the data source
        static private class SampleData extends DefaultTableModel {
          private static Class  columnClass[]={Double.class, String.class};
          private static String columnNames[]={  "Transaction"  ,  "Id"  };
            public SampleData() {
              super();
              Object data[][] = {
                                  {new Double(  23),"D"}
                                , {new Double(  85),"C"}
                                , {new Double(  27),"A"}
                                , {new Double( -20),"E"}
                                , {new Double( 125),"B"}
                                , {new Double(   3),"F"}
                                , {new Double(   6),"G"}
                                , {new Double( 142),"H"}
                                , {new Double(-117),"I"}
                                , {new Double(  26),"J"}
                                , {new Double(  73),"K"}
                                , {new Double(  16),"L"}
                                , {new Double( -82),"M"}
                                , {new Double(  93),"N"}
                                , {new Double( 126),"O"}
              };
              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());
          ChangeAxis  bipGraphSample = new ChangeAxis ();

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