Sunday, August 29, 2010

Issue during create dynamically columns in Columnchart

I faced a issue during create column chart and add columns
dynamically.
My code:
private AbstractDataTable createTable(String xmldata) {
DataTable data = DataTable.create();

data.addColumn(ColumnType.STRING, "Year");
data.addColumn(ColumnType.NUMBER, "Gopal","0");
data.addColumn(ColumnType.NUMBER, "Shanthi","1");
data.addColumn(ColumnType.NUMBER, "Senthil","2");

// XML PARSE
final Document xmlDoc = XMLParser.parse(xmldata);
final Element root = xmlDoc.getDocumentElement();
XMLParser.removeWhitespace(xmlDoc);
final NodeList profiles = root.getElementsByTagName("DATA");

int rowIndex = 0, columnIndex = -1;

//data.addRows(profiles.getLength());
for (int i = 0; i < profiles.getLength(); i++) {
data.addRow();
final Element year = (Element) profiles.item(i);

int noofEmp = year.getElementsByTagName("INDIVIDUALS").getLength();

data.setValue(rowIndex, ++columnIndex, year
.getAttributeNode("YEAR").getValue());
for (int j = 0; j < noofEmp; j++) {
++columnIndex;
final Element emp = (Element) year.getElementsByTagName(
"INDIVIDUALS").item(j);
final Element emp_leave = (Element) emp.getElementsByTagName(
"T_LEAVE").item(0);
final Element emp_name = (Element) emp.getElementsByTagName(
"NAME").item(0);

//Window.alert("Num of Record"+noofEmp);
// data.addColumn(ColumnType.NUMBER, emp_name
// .getFirstChild().getNodeValue());
data.setColumnLabel(columnIndex,emp_name
.getFirstChild().getNodeValue());

//Window.alert("Name : "+emp_name
// .getFirstChild().getNodeValue());

data.setValue(rowIndex, columnIndex, Integer.parseInt(emp_leave
.getFirstChild().getNodeValue()));
//Window.alert("row Column"+data.getValueInt(rowIndex,
columnIndex));

}
rowIndex++;
columnIndex = -1;
}
//Window.alert("Row Count ,Column Count"+data.getNumberOfRows()+"
"+data.getNumberOfColumns());


return data;
}

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment