ScatterPlotOLAPDataModel: Basic Requirements

The main responsibility of a ScatterPlotOLAPDataModel is to map data measures from an OLAP data structure to variable roles in a scatter plot. In your code, you can explicitly select measures in the OLAP data, or allow the component's OLAP data model to select measures by default.

A ScatterPlot's primary variable roles are

XVariable
Specifies a variable whose values are represented along the horizontal axis. A ScatterPlotOLAPDataModel maps this role to the first measure in the OLAP structure.
YVariable
Specifies a variable whose values are represented along the left vertical axis. A ScatterPlotOLAPDataModel maps this role to the second measure in the OLAP structure.
GroupVariable
Specifies a classification variable whose values are used to generate multiple plots. A separate plot is generated for each unique value of this variable. A ScatterPlotOLAPDataModel uses this role if the OLAP axis that supplies the XVariable role has more than one level and the ScatterPlot's groupEnabled field is true.

To access OLAP data for a graph, you must know the name of the OLAP host server and connect to that server with a valid username and password. To use the OLAP data in a ScatterPlot, you must

The following code fragment generates a scatter plot that plots actual sums against predicted sums for selected products, years, and countries.


// Create strings to store an SQL query, the OLAP server name,
// and the connection port.
   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"; // use a valid server name
   int OLAP_PORT=8800;                    // use a valid port

// Create a ScatterPlotOLAPDataModel from an OLAPDataSet. The final argument
// on the model constructor sets the chart's subgroupEnabled field to false.
   ScatterPlotOLAPDataModel olapDataModel = null;
   try {
        // OLAPDataSet arguments: host, port, username, pwd, query
           olapDataModel=new ScatterPlotOLAPDataModel(
           new OLAPDataSet(OLAP_SERVER, OLAP_PORT, "myUsername", "myPwd",
                           OLAP_QUERY), false);
       } catch (Exception ex) { ex.printStackTrace(); }

// Create a ScatterPlot that uses the ScatterPlotOLAPDataModel as its data model
   ScatterPlot scatterPlot=new ScatterPlot();
   scatterPlot.setDataModel(olapDataModel);

Example
ScatterPlot Using OLAP Data: Swing-based code, Servlet-based code