-
Bug
-
Resolution: Cannot Reproduce
-
Normal
-
None
-
None
-
None
as the code below, the calculated average is grater than total value
Composer
package test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Random; import org.zkoss.pivot.Calculator; import org.zkoss.pivot.PivotField; import org.zkoss.pivot.impl.StandardCalculator; import org.zkoss.pivot.impl.TabularPivotField; import org.zkoss.pivot.impl.TabularPivotModel; import org.zkoss.zk.ui.select.SelectorComposer; /** * Tested with ZK 6.0.1 CE and ZK Pivottable 2.0.0 * */ @SuppressWarnings("rawtypes") public class TestComposer extends SelectorComposer { /** * generated serial version UID */ private static final long serialVersionUID = -2897873399288955635L; private TabularPivotModel _pivotModel; /** * Get pivottable's model * @return TabularPivotModel the pivottable's model * @throws Exception */ public TabularPivotModel getPivotModel () throws Exception { if (_pivotModel == null) { _pivotModel = new TabularPivotModel(getData(), getColumns()); // assign rows, the order matches to the level of row node field _pivotModel.setFieldType("Row_Level_001", PivotField.Type.ROW); _pivotModel.setFieldType("Row_Level_002", PivotField.Type.ROW); _pivotModel.setFieldType("Row_Level_003", PivotField.Type.ROW); _pivotModel.setFieldType("Row_Level_004", PivotField.Type.ROW); // assign columns, the order matches to the level of column node field _pivotModel.setFieldType("Column_Level_001", PivotField.Type.COLUMN); _pivotModel.setFieldType("Column_Level_002", PivotField.Type.COLUMN); // assign datas, the order matches to the order of data field _pivotModel.setFieldType("Data_Field_001", PivotField.Type.DATA); _pivotModel.setFieldType("Data_Field_002", PivotField.Type.DATA); _pivotModel.setFieldType("Data_Field_003", PivotField.Type.DATA); TabularPivotField field = _pivotModel.getField("Row_Level_001"); _pivotModel.setFieldSubtotals(field, new Calculator[]{ StandardCalculator.AVERAGE }); field = _pivotModel.getField("Row_Level_002"); _pivotModel.setFieldSubtotals(field, new Calculator[]{ StandardCalculator.AVERAGE }); field = _pivotModel.getField("Row_Level_003"); _pivotModel.setFieldSubtotals(field, new Calculator[]{ StandardCalculator.AVERAGE }); } return _pivotModel; } /** * prepare the data for pivottable's model * The order of object put into data list matches * the order of column name's order * @return * @throws Exception */ public List<List<Object>> getData() throws Exception { List<List<Object>> result = new ArrayList<List<Object>>(); Random r = new Random(); for (int i = 0; i < 10000; i++) { List<Object> data = new ArrayList<Object>(); data.add("Row_Level_001 - " + (r.nextInt(10) + 1)); data.add("Row_Level_002 - " + (r.nextInt(10) + 1)); data.add("Row_Level_003 - " + (r.nextInt(10) + 1)); data.add("Row_Level_004 - " + (r.nextInt(10) + 1)); data.add("Column_Level_001 - " + (r.nextInt(10) + 1)); data.add("Column_Level_002 - " + (r.nextInt(10) + 1)); data.add(r.nextInt(10000)); data.add(r.nextDouble() * 10000.0); data.add(r.nextInt(100)); result.add(data); } return result; } /** * prepare columns name for pivottable's model * @return */ public List<String> getColumns() { return Arrays.asList(new String[]{ "Row_Level_001", "Row_Level_002", "Row_Level_003", "Row_Level_004", "Column_Level_001", "Column_Level_002", "Data_Field_001", "Data_Field_002", "Data_Field_003" }); } }
zul
<zk> <!-- Tested with ZK 6.0.1 CE and ZK Pivottable 2.0.0 --> <!-- window, apply a SelectorComposer --> <window id="win" xmlns:w="client" apply="test.TestComposer"> <!-- pivottable, get model from window's composer --> <pivottable id="pivottable" model="${win$composer.pivotModel}" /> </window> </zk>