Working with dimensions, measures, and levels
The actuate.xtabanalyzer.Crosstab class represents the cross tab element. Use
this cross tab class when working with Interactive Crosstabs and the XTabAnalyzer viewer. Use the functions in the actuate.xtabanalyzer.Dimension class to add, remove, or modify dimensions. Use the functions in the actuate.xtabanalyzer.Measure class to add, remove, or modify measures. Use the functions in the actuate.xtabanalyzer.Level class to add, remove, or modify levels. These classes contain functions that support the creation and modification of the dimensions, measures, and levels in the cross tab. These functions work with information from a data cube that is created with BIRT Designer Professional.
Adding a dimension with levels
To add a dimension to the cross tab, use Crosstab.addDimension( ) to add an actuate.xtabanalyzer.Dimension object to the cross tab. The following code requires that the dimensions and levels already exist within a data cube:
var crosstab = new actuate.xtabanalyzer.Crosstab( );
var dimension = new actuate.xtabanalyzer.Dimension( );
// Set dimension to be in the zero location.
var level = new actuate.xtabanalyzer.Level( );
var level = new actuate.xtabanalyzer.Level( );
var level = new actuate.xtabanalyzer.Level( );
crosstab.submit( );
Removing a dimension
To remove a dimension from a cross tab, use Crosstab.removeDimension( ). In this example, levelNames is an array of strings containing the names of the levels to remove:
crosstab.submit( );
Adding and removing measures
To add a measure to the cross tab, use Crosstab.addMeasure( ). The addMeasure( ) function accepts an actuate.xtabanalyzer.Measure object as a parameter. This example creates a new measure and adds it to a cross tab:
var measure = new actuate.xtabanalyzer.Measure( );
measure.setMeasureName("Quarter Rate");
crosstab.submit( );
The measure.setExpression( ) function dynamically sets the measure to display the revenue received for sales data, organized by year and product line. In this example, the expression is in EasyScript. EasyScript is described in Using Actuate BIRT Designer Professional. The expression in the example is the database field
that contains the sales revenue value. Interactive Crosstabs aggregates the sales revenue value for each year for each product line. The [revenue_SalesDate
/year_Product/PRODUCTLINE] string specifies that the expression applies to the revenue by sales date and then by year for the product line.
The Actuate JavaScript API combined with standard JavaScript functionality enables the creation of web pages that allow for interactive manipulation of cross tabs. In this example, the measure name and the measure expression are retrieved from HTML elements with the names of measureName and measureExpression. As coded, these elements can be an item such as a text entry field. The values of any used elements then go into the new measure for the cross tab.
var measureName = document.getElementById("measureName").value;
var measureExpression = document.getElementById("measureExpression").value;
var measure = new actuate.xtabanalyzer.Measure( );
crosstab.submit( );
The web page must contain elements with the IDs of measureName and measureExpression. Use the following HTML code to create these elements:
<INPUT TYPE="text" SIZE="60" ID="measureName" VALUE="Quarter Rate">
<INPUT type="text" SIZE="60" ID="measureExpression" VALUE="[revenue]/[revenue_SalesDate/year_Product/PRODUCTLINE]">
Use removeMeasure( ) to remove a measure. Pass the name of the measure to remove to removeMeasure( ).
crosstab.removeMeasure("Quarter Rate");
crosstab.submit( );
Changing measures and dimensions
Edit measures with Crosstab.editMeasure( ). In this example, the measureName measure named measureName takes on a new value:
var measure = new actuate.xtabanalyzer.Measure( );
crosstab.submit( );
Use Crosstab.changeMeasureDirection( ) to change the measure direction. Pivot the cross tab with Crosstab.pivot( ).
Use Crosstab.reorderDimension( ) to change the order or axis type of a dimension within a cross tab. This example moves the index of a dimension within a cross tab from 1 to 5. The dimension’s axis type changes from a row axis to a column axis.
var dimIdx = 1;
var newDimIdx = 5
var axis = actuate.xtabanalyzer.Dimension.ROW_AXIS_TYPE;
var newAxis = actuate.xtabanalyzer.Dimension.COLUMN_AXIS_TYPE;
crosstab.reorderDimension(dimIdx,axis,newDimIdx,newAxis );
crosstab.submit( );
The measure placement order can be altered using Crosstab.reorderMeasure( ). In this example, a measure’s index changes from position 1 in the cross tab to position 5:
crosstab.submit( );
Measures and dimensions can also be changed with the functions in the measure and dimension classes. In this example, a dimension axis changes from column to row:
var currentAxis = dimension.getAxisType( )
if (currentAxis == actuate.xtabanalyzer.Dimension.COLUMN_AXIS_TYPE){