BarLineChartOLAPDataModel: Basic Requirements

The main responsibility of a BarLineChartOLAPDataModel is to map data members from an OLAP data structure to variable roles in a BarLine chart.

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 BarLine chart's primary variable roles are

CategoryVariable
Specifies a classification variable whose values determine the number and arrangement of bars in the chart. A unique bar element is produced for each unique classification value or combination of values when other variable roles are specified. A BarLineChartOLAPDataModel maps this role to an OLAP column or row level, depending on the OLAP structure.
BarResponseVariable
Specifies an analysis variable whose values determine the height of each bar. A BarLineChartOLAPDataModel maps this role to the first measure in the OLAP structure.
LineResponseVariable
Specifies an analysis variable whose values are used for the plot line(s). A BarLineChartOLAPDataModel maps this role to the second and subsequent measures in the OLAP structure. Each measure generates a separate line.
SubgroupVariable
Divides bars into subgroup segments, and generates a separate line for each subgroup value. A BarLineChartOLAPDataModel uses this role if the OLAP axis that supplies the CategoryVariable role has more than one level and the BarLineChart's subgroupEnabled 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 BarLineChart, you must

The following code fragment generates a BarLine chart that shows product 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 BarLineChartOLAPDataModel from an OLAPDataSet. The final argument
// on the model constructor sets the chart's subgroupEnabled field to false.
   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(); }

// Create a BarLineChart that uses the BarLineChartOLAPDataModel as its data model
   BarLineChart barLineChart=new BarLineChart();
   barLineChart.setDataModel(olapDataModel);

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