IcCube - Cumulative Total in Chart
I have an icCube sequential chart that displays a measure for a list of items, ordered from large to small.
I would like to use to display the cumulative sum without using MDX, but using a function expression constructor. Unfortunately, I cannot get it to work. I'm probably something wrong in the syntax.
Does anyone know how to create a javascript construct to get the cumulative value.
For example. MDX result gives:
- item1 10
- item2 6
- item3 2
I want the widget to render data like:
- item1 10
- item2 16 (10 + 6)
- item3 18 (10 + 6 + 2)
And - please - pure javascript in defining the value in the graph using functions from the library.
source to share
In the Data Render part, widget, we need to define a javascript function as a value field. We'll add a function to calculate the cumulative values โโdirectly, but we can use:
var ri = context.rowIndex; // current row Index
var cumVal = 0;
var isNotNull = false; // we've to add an ic3Add that supports nulls/empty
for ( var row = 0 ; row <= ri; row++ ) { // all former including this
var cellVal = context.getValue(row);
cumVal += cellVal || 0 ; // handle 'empty'
isNotNull = isNotNull || cellVal;
}
// the job is done
if (isNotNull)
return cumVal;
else
return
Update for icCube v 6.2 (4285)
icCube 6.2 introduced new cumulative features:
cumulativeRow(row:CtxCoord, measure?:CtxCoord, property?:string):number
cumulativeCol(column:CtxCoord, measure?:CtxCoord, property?:string):number
cumulativeTable(row:CtxCoord, column:CtxCoord, measure?:CtxCoord, property?:string):number
With these new functions, the new value for the Value property should be:
return context.cumulativeRow();
source to share