<% // 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 scatter plot that shows product sums
// for selected products and years. 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 ScatterPlotOLAPDataModel. The model's constructor
//       specifies the OLAPDataSet as an argument.
//    3) Creates an OLAPScatterPlot and specifies the
//       ScatterPlotOLAPDataModel as its data model.
%>

<%@page import="
        com.sas.servlet.tbeans.olapgraphics.html.OLAPScatterPlot,
        com.sas.graphics.components.scatterplot.ScatterPlotOLAPDataModel,
        com.sas.storage.olap.sasmdx.OLAPDataSet"
%>

<%
   // 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 PRDMDDB"; // specify valid OLAP source
   String OLAP_SERVER="myOLAPServer.com"; // specify a valid server name
   int OLAP_PORT=9999; // specify a valid port

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

<% 
   // 3) Create an OLAPScatterPlot and specify the
   // ScatterPlotOLAPDataModel as its data model.
      OLAPScatterPlot scatterPlot=new OLAPScatterPlot();
      scatterPlot.setDataModel(olapDataModel);

   // Set a width and height for the chart
      scatterPlot.setWidth(640);
      scatterPlot.setHeight(520);

   // Set HTTP-specific response and request functionality
      scatterPlot.setResponse(response);
      scatterPlot.setRequest(request);
	
   // Write the chart to the display
      scatterPlot.write(out);
%>