// UseOLAPData:


// To use OLAP data, you must know the name of the OLAP host server and
// connect to that server using a valid username and password. To build
// a graph, you can pass a valid MDX query statement to the OLAP server.

/************************************************************************
 * To run this sample, you must edit the String and int declarations    *
 * below so that they define a valid MDX query, username, and password  *
 * for accessing your OLAP data                                         *
 ************************************************************************/

// This sample application generates a bar chart that shows product sums
// for selected products, years, and countries. The sample
//    1) Creates strings to store the MDX query, the OLAP server name,
//       and the connection port. The result set from the query is
//       used to create an OLAPDataSet.
//    2) Creates a BarLineChartOLAPDataModel. The model's constructor
//       specifies the OLAPDataSet as an argument.
//    3) Creates a BarLineChart and specifies the
//       BarLineChartOLAPDataModel as its data model.

   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 com.sas.storage.olap.sasmdx.OLAPDataSet;
   import com.sas.graphics.components.barlinechart.BarLineChart;
   import com.sas.graphics.components.barlinechart.BarLineChartOLAPDataModel;

   public class UseOLAPData extends JPanel  {
     private UseOLAPData  theApp;

   // 1) Create strings to store the MDX query, the OLAP server name,
   // and an int to store the connection port.

   /******* modify query to access your data **********/
   String OLAP_QUERY="SELECT "
                   + "{[PRODUCTLINE].[PRODUCT].MEMBERS} ON COLUMNS,"
                   + "CROSSJOIN({[TIME].[YEAR].MEMBERS},"
                   + "{[Measures].[ACTUAL_SUM],[Measures].[PREDICT_SUM]}) ON ROWS "
                   + "FROM MYOLAPCUBE";   // specify a valid OLAP data source
   String OLAP_SERVER="myOlapServer.com"; // specify a valid server name
   int OLAP_PORT=8800;                    // specify a valid port

      public UseOLAPData () {
        setLayout(new BorderLayout());

       // 2) Create a BarLineChartOLAPDataModel and specify
       // an OLAPDataSet as an argument on the constructor.
          BarLineChartOLAPDataModel olapDataModel = null;
          try {
              // OLAPDataSet arguments: host, port, username, pwd, query
              olapDataModel=new BarLineChartOLAPDataModel(
                new OLAPDataSet(OLAP_SERVER, OLAP_PORT, "myUsername", "myPwd",
                                OLAP_QUERY), false);
              } catch (Exception ex) { ex.printStackTrace(); }

       // 3) Create a BarLineChart and specify the
       // BarLineChartOLAPDataModel as its data model.
          BarLineChart barLineChart=new BarLineChart();
          barLineChart.setDataModel(olapDataModel);
          add(barLineChart, BorderLayout.CENTER);
      }
      public static void main(String[] args) {
      	  JFrame frame = new JFrame("Use OLAP Data");
      	  Container container = frame.getContentPane();
          container.setLayout(new BorderLayout());
          container.setBackground(Color.white);

          JPanel bipPanel = new JPanel();
          bipPanel.setLayout(new BorderLayout());
          UseOLAPData  olapSample = new UseOLAPData ();

          bipPanel.add(olapSample, BorderLayout.CENTER);
          container.add(bipPanel, BorderLayout.CENTER);

          frame.setSize(640,520);
          frame.addWindowListener(new WindowAdapter() {
              public void windowClosing(WindowEvent e) {
                     System.exit(0);
              }
          } );
          frame.setVisible(true);
      }
   }