Please find the attached pdf.
My Button Click Code. iconExportButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
DSRequest requestProperties = new DSRequest();
requestProperties.setContentType("application/pdf");
requestProperties.setAttribute("skinName", "Enterprise");
requestProperties.setAttribute("pdfName", "Dashboard_Report");
requestProperties.setExportToClient(true);
requestProperties.setExportPath("/exportDashboard/");
requestProperties.setDownloadResult(true);
requestProperties.setExportHeader("Case Report");
requestProperties.setServerOutputAsString(false);
RPCManager.exportContent(dashboardView.getView(), requestProperties); }
});
How i am creating ListGrid package com.tetrus.prea.client.app.ui;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.google.gwt.i18n.shared.DateTimeFormat;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.ChartType;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.types.SelectionStyle;
import com.smartgwt.client.types.TitleOrientation;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
import com.smartgwt.client.widgets.form.fields.RadioGroupItem;
import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
import com.tetrus.prea.client.app.model.CaseStatisticsRecord;
import com.tetrus.prea.client.utils.CommonUtils;
import com.tetrus.prea.client.utils.DashboardUtils;
import com.tetrus.prea.client.utils.FormItemType;
import com.tetrus.prea.shared.DashboardConstant;
import com.tetrus.prea.shared.DashboardDTO;
import com.tetrus.prea.shared.FacilityDTO;
import com.tetrus.prea.shared.RowDTO;
public class CaseDashboardView {
private VLayout lytMain;
private VLayout lytBody;
private RadioGroupItem caseTypes;
private RadioGroupItem formTypesRadio;
private ListGrid lgridCaseStatistics;
private ComboBoxItem facilityItem;
private final Map<String, FacilityDTO> mapFacilities;
private DashboardSChart dashboardSChart;
private final boolean useGhart = true;
private String chartLib = DashboardUtils.GOOGLE_VISUALIZATION;
private Label lblNodata;
private List<RowDTO> data;
public String type;
public String fac;
public CaseDashboardView() {
init();
}
public void clearAll() {
showColumnChart(null);
CaseStatisticsRecord[] data = null;
lgridCaseStatistics.setData(data);
lgridCaseStatistics.setData(new ListGridRecord[] {});
final ListGridRecord[] emptyData = lgridCaseStatistics.getRecords();
if (emptyData != null)
for (final ListGridRecord rec : emptyData)
lgridCaseStatistics.removeData(rec);
}
private String[] getCaseTypeValues() {
final String[] data = new String[4];
data[0] = DashboardConstant.CaseType.toString();
data[1] = DashboardConstant.Outcomes.toString();
data[2] = DashboardConstant.CaseTotal.toString();
data[3] = DashboardConstant.OperationalStatistics.toString();
return data;
}
private DashboardConstant getConstantFromValue(final String caseType) {
DashboardConstant type = null;
if (!CommonUtils.isEmptyString(caseType))
if (DashboardConstant.CaseType.toString().equals(caseType))
type = DashboardConstant.CaseType;
else if (DashboardConstant.Outcomes.toString().equals(caseType))
type = DashboardConstant.Outcomes;
else if (DashboardConstant.CaseTotal.toString().equals(caseType))
type = DashboardConstant.CaseTotal;
else if (DashboardConstant.OperationalStatistics.toString().equals(caseType))
type = DashboardConstant.OperationalStatistics;
return type;
}
private Options getOptions() {
final Options options = Options.create();
options.setTitle(" ");
options.setWidth(800);
options.setHeight(400);
return options;
}
private CaseStatisticsRecord[] getRecords(final List<RowDTO> data) {
CaseStatisticsRecord[] records = null;
if (data != null && data.size() > 0) {
records = new CaseStatisticsRecord[data.size()];
int i = 0;
for (final RowDTO rowData : data) {
final String heading = DashboardChart.setAxisLabelCharts(rowData.getHeading().toString());
final CaseStatisticsRecord rec = new CaseStatisticsRecord(heading, rowData.getCurrentYear(), rowData.getLastYear(), rowData.getYearBefore());
records[i++] = rec;
}
}
return records;
}
private DataTable getTableData(final List<RowDTO> data) {
final DataTable tableData = DataTable.create();
tableData.addColumn(ColumnType.STRING, "Type");
tableData.addColumn(ColumnType.NUMBER, "Current Year");
tableData.addColumn(ColumnType.NUMBER, "Last Year");
tableData.addColumn(ColumnType.NUMBER, "Year Before Last");
if (data != null && data.size() > 0) {
int i = 0;
for (final RowDTO rowData : data) {
tableData.addRow();
tableData.setValue(i, 0, rowData.getHeading());
tableData.setValue(i, 1, rowData.getCurrentYear());
tableData.setValue(i, 2, rowData.getLastYear());
tableData.setValue(i, 3, rowData.getYearBefore());
i++;
}
}
return tableData;
}
public VLayout getView() {
return lytMain;
}
private void init() {
lytMain = new VLayout();
lytMain.setWidth100();
lytMain.setHeight100();
lytMain.setMargin(5);
lytMain.setMembersMargin(15);
lytMain.setOverflow(Overflow.AUTO);
initHeaderControls();
initGraphArea();
initDataGrid();
}
private void initDataGrid() {
lgridCaseStatistics = new ListGrid();
lgridCaseStatistics.setShowRecordComponents(true);
lgridCaseStatistics.setShowRecordComponentsByCell(true);
lgridCaseStatistics.setShowAllRecords(true);
lgridCaseStatistics.setWidth100();
lgridCaseStatistics.setHeight(200);
lgridCaseStatistics.setLeaveScrollbarGap(false);
lgridCaseStatistics.setShowHeaderContextMenu(false);
lgridCaseStatistics.setCanSort(false);
lgridCaseStatistics.setSelectionType(SelectionStyle.SINGLE);
lgridCaseStatistics.setCellHeight(25);
lgridCaseStatistics.setHeaderBaseStyle("cellTableHeaderStyleCenter");
lgridCaseStatistics.setHeaderTitleStyle("listGridGeaderTitleStyleCenter");
lgridCaseStatistics.setAlternateRecordStyles(true);
lgridCaseStatistics.setAlternateBodyStyleName("searchResultListAlternateStyle");
lgridCaseStatistics.setBodyStyleName("searchResultListBodyStyle");
lgridCaseStatistics.setAutoChildProperties("chart", dashboardSChart);
lgridCaseStatistics.setChartType(ChartType.COLUMN);
Date date = new Date();
DateTimeFormat format = DateTimeFormat.getFormat("yyyy");
String year = format.format(date);
int currentYear = Integer.parseInt(year);
int lastYear = currentYear - 1;
int yearBeforeLast = lastYear - 1;
final ListGridField type = new ListGridField("type", "Type");
type.setWidth("*");
type.setHeaderBaseStyle("cellTableHeaderStyle");
type.setHeaderTitleStyle("cellTableHeaderStyle");
final ListGridField currYearField = new ListGridField("currYear", "Current Year" + " (" + currentYear + ") ");
currYearField.setWidth("20%");
currYearField.setAlign(Alignment.CENTER);
final ListGridField lastYearField = new ListGridField("lastYear", "Last Year" + " (" + String.valueOf(lastYear) + ") ");
lastYearField.setWidth("20%");
lastYearField.setAlign(Alignment.CENTER);
final ListGridField yearLastBeforeField = new ListGridField("yearLastBefore", "Year Before Last" + " (" + String.valueOf(yearBeforeLast) + ") ");
yearLastBeforeField.setWidth("20%");
yearLastBeforeField.setAlign(Alignment.CENTER);
lgridCaseStatistics.setFields(type, currYearField, lastYearField, yearLastBeforeField);
setLgridCaseStatistics(lgridCaseStatistics);
lytMain.addMember(lgridCaseStatistics);
}
private void initGraphArea() {
lytBody = new VLayout();
lytBody.setHeight(400);
lytBody.setWidth100();
lytBody.setOverflow(Overflow.VISIBLE);
lytBody.setAlign(Alignment.CENTER);
lblNodata = new Label("No data to display");
lblNodata.setAlign(Alignment.CENTER);
dashboardSChart = new DashboardSChart();
dashboardSChart.setPrintChildrenAbsolutelyPositioned(true);
dashboardSChart.setPrintZoomChart(true);
lytMain.addMember(lytBody);
}
private void initHeaderControls() {
final Label text = new Label("Statistics dashboard");
text.setWrap(false);
text.setHeight("25px");
text.setStyleName("searchSection-title");
text.setMargin(5);
final VLayout lytTop = new VLayout();
lytTop.setStyleName("dashboard-HeaderStyle");
lytTop.setMargin(5);
lytTop.setMembersMargin(5);
lytTop.setHeight(70);
lytTop.addMember(text);
final HLayout lytControls = new HLayout();
lytControls.setHeight(50);
lytControls.setMembersMargin(10);
final DynamicForm formTypes = new DynamicForm();
formTypes.setTitleSuffix(" ");
formTypes.setBorder("1px solid gray");
formTypes.setWidth(250);
formTypes.setMargin(5);
formTypes.setAlign(Alignment.CENTER);
formTypesRadio = (RadioGroupItem) CommonUtils.getFormItem(FormItemType.RADIO, " Form Type");
formTypesRadio.setVertical(false);
formTypesRadio.setWrap(false);
formTypesRadio.setValueMap("Adult", "Juvenile");
formTypes.setItems(formTypesRadio);
final DynamicForm formCaseTypes = new DynamicForm();
formCaseTypes.setTitleSuffix(" ");
formCaseTypes.setBorder("1px solid gray");
formCaseTypes.setWidth(600);
formCaseTypes.setMargin(5);
formCaseTypes.setAlign(Alignment.CENTER);
caseTypes = (RadioGroupItem) CommonUtils.getFormItem(FormItemType.RADIO, " ");
caseTypes.setVertical(false);
caseTypes.setWrap(false);
caseTypes.setValueMap(getCaseTypeValues());
caseTypes.addChangedHandler(new CaseTypeFacilityChangedHandler());
formCaseTypes.setItems(caseTypes);
final DynamicForm formFacility = new DynamicForm();
formFacility.setTitleSuffix(" ");
facilityItem = (ComboBoxItem) CommonUtils.getFormItem(FormItemType.COMBO_BOX, "Facility");
facilityItem.setTitleOrientation(TitleOrientation.TOP);
facilityItem.setWidth(300);
facilityItem.addChangedHandler(new CaseTypeFacilityChangedHandler());
formFacility.setItems(facilityItem);
lytControls.addMember(formCaseTypes);
lytControls.addMember(formFacility);
lytTop.addMember(lytControls);
lytMain.addMember(lytTop);
lytMain.addMember(new DashboardToolBar().getReportToolBar(this));
}
public void setChartProperties(final Map<String, String> mapProps) {
if (mapProps != null)
chartLib = mapProps.get(DashboardUtils.CHART_LIB);
}
private void setContentForFacility(final String facName) {
if (!CommonUtils.isEmptyString(facName)) {
final FacilityDTO facility = mapFacilities.get(facName);
if (facility != null) {
final Map<DashboardConstant, List<RowDTO>> mapValues = facility.getVisualizationMap();
final Set<DashboardConstant> setKeys = mapValues.keySet();
final Iterator<DashboardConstant> iterator = setKeys.iterator();
final List<String> lstCaseTypes = new ArrayList<String>();
while (iterator.hasNext()) {
final DashboardConstant dashboardConstant = iterator.next();
lstCaseTypes.add(dashboardConstant.toString());
}
if (lstCaseTypes != null && lstCaseTypes.size() > 0) {
final String[] values = new String[lstCaseTypes.size()];
lstCaseTypes.toArray(values);
if (values != null && values.length > 0)
setListGridData(facName, DashboardConstant.CaseType.toString());
}
}
}
}
public void setData(DashboardDTO dashboardDTO) {
if (dashboardDTO != null) {
List<FacilityDTO> lstFacilities = dashboardDTO.getFacilityDTOList();
if (lstFacilities != null) {
List<String> facilityNames = new ArrayList<String>();
for (FacilityDTO fac : lstFacilities) {
facilityNames.add(fac.getFacilityName());
mapFacilities.put(fac.getFacilityName(), fac);
}
if (lstFacilities.size() == 2) {
String[] facValues = new String[2];
facilityNames.remove("All");
facilityNames.add("");
facilityNames.toArray(facValues);
facilityItem.setValueMap(facValues);
} else {
String[] facValues = new String[facilityNames.size()];
facilityNames.toArray(facValues);
facilityItem.setValue("All");
facilityItem.setValueMap(facValues);
}
if (lstFacilities.get(0) != null)
setContentForFacility(lstFacilities.get(0).getFacilityName());
}
}
}
private void setListGridData(final String facilityName, final String caseType) {
if (!CommonUtils.isEmptyString(facilityName) && !CommonUtils.isEmptyString(caseType)) {
caseTypes.setValue(caseType);
final FacilityDTO facility = mapFacilities.get(facilityName);
if (facility != null) {
final Map<DashboardConstant, List<RowDTO>> mapValues = facility.getVisualizationMap();
final DashboardConstant type = getConstantFromValue(caseType);
final List<RowDTO> data = mapValues.get(type);
this.setData(data);
if (data != null && data.size() > 0) {
showColumnChart(data);
lgridCaseStatistics.setData(getRecords(data));
} else {
clearAll();
final ListGridRecord[] emptyData = lgridCaseStatistics.getRecords();
if (emptyData != null)
for (final ListGridRecord rec : emptyData)
lgridCaseStatistics.removeData(rec);
}
}
}
}
private void showColumnChart(final List<RowDTO> data) {
if (data != null && data.size() > 0)
dashboardSChart.setData(data);
VLayout layout = new VLayout();
layout.setWidth100();
layout.setHeight100();
layout.addMembers(dashboardSChart);
layout.draw();
lytBody.addMember(layout);
} else {
lytBody.removeMembers(lytBody.getMembers());
lytBody.addMember(lblNodata);
}
}
public List<RowDTO> getData() {
return data;
}
public void setData(List<RowDTO> data) {
this.data = data;
}
}
How I have created Chart /**
*
*/
package com.client.app.ui;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.types.Autofit;
import com.smartgwt.client.widgets.chart.FacetChart;
import com.smartgwt.client.widgets.cube.Facet;
import com.smartgwt.client.widgets.events.ShowContextMenuEvent;
import com.smartgwt.client.widgets.events.ShowContextMenuHandler;
import com.tetrus.prea.shared.RowDTO;
public class DashboardSChart extends FacetChart {
//final String[] barColors = { "blue", "red", "green" };
final int MAX_REVENUE = 1000;
final int WIDTH = 300;
final int HEIGHT = 400;
public DashboardSChart() {
this.setXAxisStartValue(0.0D);
this.setFacets(new Facet("type", "Type"), new Facet("year", "Year"));
this.setValueProperty("count");
this.setTitle("Dashboard");
this.setStacked(Boolean.FALSE);
this.setWidth100();
this.setHeight100();
this.addShowContextMenuHandler(new ShowContextMenuHandler() {
@Override
public void onShowContextMenu(ShowContextMenuEvent event) {
event.cancel();
}
});
}
public void setData(List<RowDTO> data) {
final Date date = new Date();
int currentYear = date.getYear() + 1900;
String curYrLbl = "Current Year (" +currentYear + ")";
String preYrLbl = "Last Year ("+ (currentYear - 1) + ")";
String ystYrLbl = "Year Before Last ("+ (currentYear - 2) + ")";
if (data != null) {
List<Record> records = new ArrayList<Record>(data.size() * 3);
for(RowDTO dto : data){
records.add(createRecord(dto.getHeading(), curYrLbl, dto.getCurrentYear()));
records.add(createRecord(dto.getHeading(), preYrLbl, dto.getLastYear() + 5));
records.add(createRecord(dto.getHeading(), ystYrLbl, dto.getYearBefore() + 8));
}
this.setData(records.toArray(new Record[records.size()]));
}
}
private Record createRecord(final String type, final String year, final int count){
Record record = new Record();
record.setAttribute("type", type);
record.setAttribute("year", year);
record.setAttribute("count", count);
return record;
}
}
My Button Click Code. iconExportButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
DSRequest requestProperties = new DSRequest();
requestProperties.setContentType("application/pdf");
requestProperties.setAttribute("skinName", "Enterprise");
requestProperties.setAttribute("pdfName", "Dashboard_Report");
requestProperties.setExportToClient(true);
requestProperties.setExportPath("/exportDashboard/");
requestProperties.setDownloadResult(true);
requestProperties.setExportHeader("Case Report");
requestProperties.setServerOutputAsString(false);
RPCManager.exportContent(dashboardView.getView(), requestProperties); }
});
How i am creating ListGrid package com.tetrus.prea.client.app.ui;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.google.gwt.i18n.shared.DateTimeFormat;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.ChartType;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.types.SelectionStyle;
import com.smartgwt.client.types.TitleOrientation;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
import com.smartgwt.client.widgets.form.fields.RadioGroupItem;
import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
import com.tetrus.prea.client.app.model.CaseStatisticsRecord;
import com.tetrus.prea.client.utils.CommonUtils;
import com.tetrus.prea.client.utils.DashboardUtils;
import com.tetrus.prea.client.utils.FormItemType;
import com.tetrus.prea.shared.DashboardConstant;
import com.tetrus.prea.shared.DashboardDTO;
import com.tetrus.prea.shared.FacilityDTO;
import com.tetrus.prea.shared.RowDTO;
public class CaseDashboardView {
private VLayout lytMain;
private VLayout lytBody;
private RadioGroupItem caseTypes;
private RadioGroupItem formTypesRadio;
private ListGrid lgridCaseStatistics;
private ComboBoxItem facilityItem;
private final Map<String, FacilityDTO> mapFacilities;
private DashboardSChart dashboardSChart;
private final boolean useGhart = true;
private String chartLib = DashboardUtils.GOOGLE_VISUALIZATION;
private Label lblNodata;
private List<RowDTO> data;
public String type;
public String fac;
public CaseDashboardView() {
init();
}
public void clearAll() {
showColumnChart(null);
CaseStatisticsRecord[] data = null;
lgridCaseStatistics.setData(data);
lgridCaseStatistics.setData(new ListGridRecord[] {});
final ListGridRecord[] emptyData = lgridCaseStatistics.getRecords();
if (emptyData != null)
for (final ListGridRecord rec : emptyData)
lgridCaseStatistics.removeData(rec);
}
private String[] getCaseTypeValues() {
final String[] data = new String[4];
data[0] = DashboardConstant.CaseType.toString();
data[1] = DashboardConstant.Outcomes.toString();
data[2] = DashboardConstant.CaseTotal.toString();
data[3] = DashboardConstant.OperationalStatistics.toString();
return data;
}
private DashboardConstant getConstantFromValue(final String caseType) {
DashboardConstant type = null;
if (!CommonUtils.isEmptyString(caseType))
if (DashboardConstant.CaseType.toString().equals(caseType))
type = DashboardConstant.CaseType;
else if (DashboardConstant.Outcomes.toString().equals(caseType))
type = DashboardConstant.Outcomes;
else if (DashboardConstant.CaseTotal.toString().equals(caseType))
type = DashboardConstant.CaseTotal;
else if (DashboardConstant.OperationalStatistics.toString().equals(caseType))
type = DashboardConstant.OperationalStatistics;
return type;
}
private Options getOptions() {
final Options options = Options.create();
options.setTitle(" ");
options.setWidth(800);
options.setHeight(400);
return options;
}
private CaseStatisticsRecord[] getRecords(final List<RowDTO> data) {
CaseStatisticsRecord[] records = null;
if (data != null && data.size() > 0) {
records = new CaseStatisticsRecord[data.size()];
int i = 0;
for (final RowDTO rowData : data) {
final String heading = DashboardChart.setAxisLabelCharts(rowData.getHeading().toString());
final CaseStatisticsRecord rec = new CaseStatisticsRecord(heading, rowData.getCurrentYear(), rowData.getLastYear(), rowData.getYearBefore());
records[i++] = rec;
}
}
return records;
}
private DataTable getTableData(final List<RowDTO> data) {
final DataTable tableData = DataTable.create();
tableData.addColumn(ColumnType.STRING, "Type");
tableData.addColumn(ColumnType.NUMBER, "Current Year");
tableData.addColumn(ColumnType.NUMBER, "Last Year");
tableData.addColumn(ColumnType.NUMBER, "Year Before Last");
if (data != null && data.size() > 0) {
int i = 0;
for (final RowDTO rowData : data) {
tableData.addRow();
tableData.setValue(i, 0, rowData.getHeading());
tableData.setValue(i, 1, rowData.getCurrentYear());
tableData.setValue(i, 2, rowData.getLastYear());
tableData.setValue(i, 3, rowData.getYearBefore());
i++;
}
}
return tableData;
}
public VLayout getView() {
return lytMain;
}
private void init() {
lytMain = new VLayout();
lytMain.setWidth100();
lytMain.setHeight100();
lytMain.setMargin(5);
lytMain.setMembersMargin(15);
lytMain.setOverflow(Overflow.AUTO);
initHeaderControls();
initGraphArea();
initDataGrid();
}
private void initDataGrid() {
lgridCaseStatistics = new ListGrid();
lgridCaseStatistics.setShowRecordComponents(true);
lgridCaseStatistics.setShowRecordComponentsByCell(true);
lgridCaseStatistics.setShowAllRecords(true);
lgridCaseStatistics.setWidth100();
lgridCaseStatistics.setHeight(200);
lgridCaseStatistics.setLeaveScrollbarGap(false);
lgridCaseStatistics.setShowHeaderContextMenu(false);
lgridCaseStatistics.setCanSort(false);
lgridCaseStatistics.setSelectionType(SelectionStyle.SINGLE);
lgridCaseStatistics.setCellHeight(25);
lgridCaseStatistics.setHeaderBaseStyle("cellTableHeaderStyleCenter");
lgridCaseStatistics.setHeaderTitleStyle("listGridGeaderTitleStyleCenter");
lgridCaseStatistics.setAlternateRecordStyles(true);
lgridCaseStatistics.setAlternateBodyStyleName("searchResultListAlternateStyle");
lgridCaseStatistics.setBodyStyleName("searchResultListBodyStyle");
lgridCaseStatistics.setAutoChildProperties("chart", dashboardSChart);
lgridCaseStatistics.setChartType(ChartType.COLUMN);
Date date = new Date();
DateTimeFormat format = DateTimeFormat.getFormat("yyyy");
String year = format.format(date);
int currentYear = Integer.parseInt(year);
int lastYear = currentYear - 1;
int yearBeforeLast = lastYear - 1;
final ListGridField type = new ListGridField("type", "Type");
type.setWidth("*");
type.setHeaderBaseStyle("cellTableHeaderStyle");
type.setHeaderTitleStyle("cellTableHeaderStyle");
final ListGridField currYearField = new ListGridField("currYear", "Current Year" + " (" + currentYear + ") ");
currYearField.setWidth("20%");
currYearField.setAlign(Alignment.CENTER);
final ListGridField lastYearField = new ListGridField("lastYear", "Last Year" + " (" + String.valueOf(lastYear) + ") ");
lastYearField.setWidth("20%");
lastYearField.setAlign(Alignment.CENTER);
final ListGridField yearLastBeforeField = new ListGridField("yearLastBefore", "Year Before Last" + " (" + String.valueOf(yearBeforeLast) + ") ");
yearLastBeforeField.setWidth("20%");
yearLastBeforeField.setAlign(Alignment.CENTER);
lgridCaseStatistics.setFields(type, currYearField, lastYearField, yearLastBeforeField);
setLgridCaseStatistics(lgridCaseStatistics);
lytMain.addMember(lgridCaseStatistics);
}
private void initGraphArea() {
lytBody = new VLayout();
lytBody.setHeight(400);
lytBody.setWidth100();
lytBody.setOverflow(Overflow.VISIBLE);
lytBody.setAlign(Alignment.CENTER);
lblNodata = new Label("No data to display");
lblNodata.setAlign(Alignment.CENTER);
dashboardSChart = new DashboardSChart();
dashboardSChart.setPrintChildrenAbsolutelyPositioned(true);
dashboardSChart.setPrintZoomChart(true);
lytMain.addMember(lytBody);
}
private void initHeaderControls() {
final Label text = new Label("Statistics dashboard");
text.setWrap(false);
text.setHeight("25px");
text.setStyleName("searchSection-title");
text.setMargin(5);
final VLayout lytTop = new VLayout();
lytTop.setStyleName("dashboard-HeaderStyle");
lytTop.setMargin(5);
lytTop.setMembersMargin(5);
lytTop.setHeight(70);
lytTop.addMember(text);
final HLayout lytControls = new HLayout();
lytControls.setHeight(50);
lytControls.setMembersMargin(10);
final DynamicForm formTypes = new DynamicForm();
formTypes.setTitleSuffix(" ");
formTypes.setBorder("1px solid gray");
formTypes.setWidth(250);
formTypes.setMargin(5);
formTypes.setAlign(Alignment.CENTER);
formTypesRadio = (RadioGroupItem) CommonUtils.getFormItem(FormItemType.RADIO, " Form Type");
formTypesRadio.setVertical(false);
formTypesRadio.setWrap(false);
formTypesRadio.setValueMap("Adult", "Juvenile");
formTypes.setItems(formTypesRadio);
final DynamicForm formCaseTypes = new DynamicForm();
formCaseTypes.setTitleSuffix(" ");
formCaseTypes.setBorder("1px solid gray");
formCaseTypes.setWidth(600);
formCaseTypes.setMargin(5);
formCaseTypes.setAlign(Alignment.CENTER);
caseTypes = (RadioGroupItem) CommonUtils.getFormItem(FormItemType.RADIO, " ");
caseTypes.setVertical(false);
caseTypes.setWrap(false);
caseTypes.setValueMap(getCaseTypeValues());
caseTypes.addChangedHandler(new CaseTypeFacilityChangedHandler());
formCaseTypes.setItems(caseTypes);
final DynamicForm formFacility = new DynamicForm();
formFacility.setTitleSuffix(" ");
facilityItem = (ComboBoxItem) CommonUtils.getFormItem(FormItemType.COMBO_BOX, "Facility");
facilityItem.setTitleOrientation(TitleOrientation.TOP);
facilityItem.setWidth(300);
facilityItem.addChangedHandler(new CaseTypeFacilityChangedHandler());
formFacility.setItems(facilityItem);
lytControls.addMember(formCaseTypes);
lytControls.addMember(formFacility);
lytTop.addMember(lytControls);
lytMain.addMember(lytTop);
lytMain.addMember(new DashboardToolBar().getReportToolBar(this));
}
public void setChartProperties(final Map<String, String> mapProps) {
if (mapProps != null)
chartLib = mapProps.get(DashboardUtils.CHART_LIB);
}
private void setContentForFacility(final String facName) {
if (!CommonUtils.isEmptyString(facName)) {
final FacilityDTO facility = mapFacilities.get(facName);
if (facility != null) {
final Map<DashboardConstant, List<RowDTO>> mapValues = facility.getVisualizationMap();
final Set<DashboardConstant> setKeys = mapValues.keySet();
final Iterator<DashboardConstant> iterator = setKeys.iterator();
final List<String> lstCaseTypes = new ArrayList<String>();
while (iterator.hasNext()) {
final DashboardConstant dashboardConstant = iterator.next();
lstCaseTypes.add(dashboardConstant.toString());
}
if (lstCaseTypes != null && lstCaseTypes.size() > 0) {
final String[] values = new String[lstCaseTypes.size()];
lstCaseTypes.toArray(values);
if (values != null && values.length > 0)
setListGridData(facName, DashboardConstant.CaseType.toString());
}
}
}
}
public void setData(DashboardDTO dashboardDTO) {
if (dashboardDTO != null) {
List<FacilityDTO> lstFacilities = dashboardDTO.getFacilityDTOList();
if (lstFacilities != null) {
List<String> facilityNames = new ArrayList<String>();
for (FacilityDTO fac : lstFacilities) {
facilityNames.add(fac.getFacilityName());
mapFacilities.put(fac.getFacilityName(), fac);
}
if (lstFacilities.size() == 2) {
String[] facValues = new String[2];
facilityNames.remove("All");
facilityNames.add("");
facilityNames.toArray(facValues);
facilityItem.setValueMap(facValues);
} else {
String[] facValues = new String[facilityNames.size()];
facilityNames.toArray(facValues);
facilityItem.setValue("All");
facilityItem.setValueMap(facValues);
}
if (lstFacilities.get(0) != null)
setContentForFacility(lstFacilities.get(0).getFacilityName());
}
}
}
private void setListGridData(final String facilityName, final String caseType) {
if (!CommonUtils.isEmptyString(facilityName) && !CommonUtils.isEmptyString(caseType)) {
caseTypes.setValue(caseType);
final FacilityDTO facility = mapFacilities.get(facilityName);
if (facility != null) {
final Map<DashboardConstant, List<RowDTO>> mapValues = facility.getVisualizationMap();
final DashboardConstant type = getConstantFromValue(caseType);
final List<RowDTO> data = mapValues.get(type);
this.setData(data);
if (data != null && data.size() > 0) {
showColumnChart(data);
lgridCaseStatistics.setData(getRecords(data));
} else {
clearAll();
final ListGridRecord[] emptyData = lgridCaseStatistics.getRecords();
if (emptyData != null)
for (final ListGridRecord rec : emptyData)
lgridCaseStatistics.removeData(rec);
}
}
}
}
private void showColumnChart(final List<RowDTO> data) {
if (data != null && data.size() > 0)
dashboardSChart.setData(data);
VLayout layout = new VLayout();
layout.setWidth100();
layout.setHeight100();
layout.addMembers(dashboardSChart);
layout.draw();
lytBody.addMember(layout);
} else {
lytBody.removeMembers(lytBody.getMembers());
lytBody.addMember(lblNodata);
}
}
public List<RowDTO> getData() {
return data;
}
public void setData(List<RowDTO> data) {
this.data = data;
}
}
How I have created Chart /**
*
*/
package com.client.app.ui;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.types.Autofit;
import com.smartgwt.client.widgets.chart.FacetChart;
import com.smartgwt.client.widgets.cube.Facet;
import com.smartgwt.client.widgets.events.ShowContextMenuEvent;
import com.smartgwt.client.widgets.events.ShowContextMenuHandler;
import com.tetrus.prea.shared.RowDTO;
public class DashboardSChart extends FacetChart {
//final String[] barColors = { "blue", "red", "green" };
final int MAX_REVENUE = 1000;
final int WIDTH = 300;
final int HEIGHT = 400;
public DashboardSChart() {
this.setXAxisStartValue(0.0D);
this.setFacets(new Facet("type", "Type"), new Facet("year", "Year"));
this.setValueProperty("count");
this.setTitle("Dashboard");
this.setStacked(Boolean.FALSE);
this.setWidth100();
this.setHeight100();
this.addShowContextMenuHandler(new ShowContextMenuHandler() {
@Override
public void onShowContextMenu(ShowContextMenuEvent event) {
event.cancel();
}
});
}
public void setData(List<RowDTO> data) {
final Date date = new Date();
int currentYear = date.getYear() + 1900;
String curYrLbl = "Current Year (" +currentYear + ")";
String preYrLbl = "Last Year ("+ (currentYear - 1) + ")";
String ystYrLbl = "Year Before Last ("+ (currentYear - 2) + ")";
if (data != null) {
List<Record> records = new ArrayList<Record>(data.size() * 3);
for(RowDTO dto : data){
records.add(createRecord(dto.getHeading(), curYrLbl, dto.getCurrentYear()));
records.add(createRecord(dto.getHeading(), preYrLbl, dto.getLastYear() + 5));
records.add(createRecord(dto.getHeading(), ystYrLbl, dto.getYearBefore() + 8));
}
this.setData(records.toArray(new Record[records.size()]));
}
}
private Record createRecord(final String type, final String year, final int count){
Record record = new Record();
record.setAttribute("type", type);
record.setAttribute("year", year);
record.setAttribute("count", count);
return record;
}
}
Comment