Skip to main content

Help with mapping data

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
2 replies [Last post]
adilsun
Offline
Joined: 2004-12-14

Hi,

I have a pivot and my pivotTableModel holds data in this fashion...
eg I have a data containing task,Year and month field values

The struture of my PivotTableModel. Below the data is being show in PivotTableModel rows...
it has theses fields
Task Year Month Values

Issued check 7 => Total checks issued
2010 4 => Total issued in 2010
Feb 3 ==> in Feb, 2011
Mar 1 ==> no of checks issued in Mar 2011
2011 3 ==> Total in 2011
Dec 3 == > issued in Dec, 2011

Now I have to show this pivot table

2011 2010 Total
Task Feb Mar Dec
Issued Checks 3 1 3 7

How to go about it?

I have a logic which tells me that user has asked for one (or more ) columns on the left and one or more columns on the top

I am havng success to show and also sort values of the left ie values of the task. but the values on the top. If single set of values I am to show. no problem, it is sorting too. but when I have more than that on the top, the top header values stop sorting and also the values against them in the table are not getting put correctly.

Thank you

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
adilsun
Offline
Joined: 2004-12-14

Please see This post for details.

adilsun
Offline
Joined: 2004-12-14

Sorry cannot show the placement of data properly Anyways, the PivotTableModel example is here as a class and with real data from the DB.

class PivotTableModel{

private String []columns ={"name","Year","Month","pivotValue","Totals"};;
private Class []columnClass ={String.class,Integer.class,Integer.class,Double.class,Double.class};;

private Object [][]rows = new Object[][]{
new Object[]{"BALANCE CONFIRMATION PROCESS",null,null,null,534.0},
new Object[]{null,2011,null,null,null},
new Object[]{null,null,3,2.0,null},
new Object[]{null,null,4,75.0,null},
new Object[]{null,null,5,149.0,null},
new Object[]{null,null,6,95.0,null},
new Object[]{null,null,7,145.0,null},
new Object[]{null,null,8,56.0,null},
new Object[]{null,null,9,12.0,null},
new Object[]{"CASH EXCESS OR SHORTAGE",null,null,null,117.0},
new Object[]{null,2011,null,null,null},
new Object[]{null,null,2,2.0,null},
new Object[]{null,null,3,9.0,null},
new Object[]{null,null,4,20.0,null},
new Object[]{null,null,5,31.0,null},
new Object[]{null,null,6,25.0,null},
new Object[]{null,null,7,13.0,null},
new Object[]{null,null,8,11.0,null},
new Object[]{null,null,9,6.0,null},
new Object[]{"CENTRAL BANK ORDER PROCESS",null,null,null,128.0},
new Object[]{null,2010,null,null,null},
new Object[]{null,null,12,2.0,null},
new Object[]{null,2011,null,null,null},
new Object[]{null,null,3,2.0,null},
new Object[]{null,null,4,15.0,null},
new Object[]{null,null,5,41.0,null},
new Object[]{null,null,6,41.0,null},
new Object[]{null,null,8,27.0,null},
new Object[]{"DECEASED ACCOUNT PROCESS",null,null,null,5.0},
new Object[]{null,2011,null,null,null},
new Object[]{null,null,2,3.0,null},
new Object[]{null,null,4,1.0,null},
new Object[]{null,null,5,1.0,null},
new Object[]{"INCIDENT REPORT PROCESS",null,null,null,1128.0},
new Object[]{null,2010,null,null,null},
new Object[]{null,null,12,2.0,null},
new Object[]{null,2011,null,null,null},
new Object[]{null,null,1,69.0,null},
new Object[]{null,null,2,169.0,null},
new Object[]{null,null,3,158.0,null},
new Object[]{null,null,4,142.0,null},
new Object[]{null,null,5,167.0,null},
new Object[]{null,null,6,177.0,null},
new Object[]{null,null,7,120.0,null},
new Object[]{null,null,8,93.0,null},
new Object[]{null,null,9,31.0,null},
new Object[]{"INCIDENT REPORTING (INCOMING)",null,null,null,1.0},
new Object[]{null,2011,null,null,null},
new Object[]{null,null,1,1.0,null}
};

public PivotTableModel(){}

public int getColumnCount() {
return (columns != null) ? columns.length : 0;
}

public String getColumnName(int columnIndex) {
return (columns != null) ? columns[columnIndex] : null;

}

public int getRowCount() {
return (rows != null) ? rows.length : 0;
}

public Object getValueAt(int rowIndex, int columnIndex) {
return (rows != null) ? rows[rowIndex][columnIndex] : null;
}

public Class getColumnClass(int columnIndex) {
return columnClass[columnIndex];
}

// just a test
public static void main(String []args){

PivotTableModel ptm = new PivotTableModel();

System.out.println(ptm.getValueAt(0,0));
System.out.println(ptm.getColumnCount());
System.out.println(ptm.getRowCount());
System.out.println(ptm.getColumnName(3));
System.out.println(ptm.getColumnClass(3));

}

}

And I need to pivot it with the structure

<table ><tr ><td ></td>
<td ></td>
<td ></td>
<td ></td>
<td >Total</td>
</tr>
<tr ><td ></td>
<td >2011</td>
<td ></td>
<td >2010</td>
<td ></td>
</tr>
<tr ><td ></td>
<td >Feb</td>
<td >Mar</td>
<td >Dec</td>
<td ></td>
</tr>
<tr ><td >Task</td>
<td ></td>
<td ></td>
<td ></td>
<td >100 (including other tasks)</td>
</tr>
<tr ><td >Issued Checks</td>
<td >3</td>
<td >1</td>
<td >3</td>
<td >7</td>
</tr>
</table>