Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    While Exporting PDF Facet charts is coming very small in size

    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;
    }

    }






    Attached Files

    #2
    We're assuming this post means that the exported chart is be smaller than you see it on screen, and you think this might be a framework issue.

    However you've missed basically everything you need in a bug report: forgot product and version, haven't tested against the latest, and your code is not runnable and not minimal.

    Please read the FAQ and the Debugging overview to understand how to troubleshoot problems, and how to report possible framework issues if you find evidence that there is such an issue.

    Comment


      #3
      Hi Team,
      I am using Smart GWT pro edition version 5.0P, with GWT 2.5.0 and jdk1.6.0_18. I have tried to export this using smart gwt showcase example http://www.smartclient.com/smartgwte...art_pdf_export also but got same result.

      Below is my onModule code. Please find the attached exported PDF , host page PREA.jsp , deployment descriptor file and my web.xml Hope it will help to reproduce the issue.
      @Override
      public void onModuleLoad() {
      final List<ListGridField> fields = new ArrayList<ListGridField>();
      fields.add(new ListGridField ("Jan", "January"));
      fields.add(new ListGridField ("Feb", "February"));
      fields.add(new ListGridField ("Mar", "March"));
      fields.add(new ListGridField ("Apr", "April"));
      fields.add(new ListGridField ("May", "May"));
      fields.add(new ListGridField ("Jun", "June"));
      fields.add(new ListGridField ("Jul", "July"));
      fields.add(new ListGridField ("Aug", "August"));
      fields.add(new ListGridField ("Sep", "September"));
      fields.add(new ListGridField ("Oct", "October"));
      fields.add(new ListGridField ("Nov", "November"));
      fields.add(new ListGridField ("Dec", "December"));

      char maxProduct = 'E';
      List<ListGridRecord> salesData = new ArrayList<ListGridRecord>();
      for (char prod = 'A'; prod <= maxProduct; prod++) {
      ListGridRecord rec = new ListGridRecord();
      rec.setAttribute("product", "Product " + prod);
      long minSales = Math.round(Math.random() * 8000) + 2000;
      long maxVariance = minSales / 3;
      for (ListGridField field : fields) {
      rec.setAttribute(field.getName(), Math.round(Math.random() * maxVariance) + minSales);
      }
      salesData.add(rec);
      }

      final ListGridField field = new ListGridField("product", "Products");
      field.setCanEdit(Boolean.FALSE);
      fields.add(0, field);

      final ListGrid grid = new ListGrid() {
      @Override
      protected String getCellStyle (ListGridRecord record, int rowNum, int colNum) {
      if ("product".equals(getFieldName(colNum))) {
      return super.getCellStyle(record, rowNum, colNum) + "Dark";
      } else {
      return super.getCellStyle(record, rowNum, colNum);
      }
      }
      };
      final FacetChart chartProperties = new FacetChart();
      chartProperties.setHeight100();
      grid.setAutoChildProperties("chart", chartProperties);
      grid.setLeaveScrollbarGap(false);
      grid.setAlternateRecordStyles(Boolean.FALSE);
      grid.setWidth100();
      grid.setAutoFitData(Autofit.VERTICAL);
      grid.setCanEdit(Boolean.TRUE);
      grid.setEditEvent(ListGridEditEvent.CLICK);
      grid.setFields(fields.toArray(new ListGridField[0]));
      grid.setData(salesData.toArray(new ListGridRecord[0]));
      grid.setChartType(ChartType.AREA);

      final FacetChart chart = grid.chartData("product");
      grid.addEditCompleteHandler(new EditCompleteHandler() {
      public void onEditComplete(EditCompleteEvent event) {
      chart.setData(grid.getRecords());
      }
      });

      final VLayout theLayout = new VLayout();

      final IButton viewAsPDFButton = new IButton("View as PDF");
      viewAsPDFButton.setWidth("50%");
      viewAsPDFButton.addClickHandler(new ClickHandler() {
      @Override
      public void onClick(ClickEvent event) {
      final DSRequest requestProperties = new DSRequest();
      requestProperties.setExportDisplay(ExportDisplay.WINDOW);
      RPCManager.exportContent(theLayout);
      }
      });
      final IButton downloadAsPDFButton = new IButton("Download as PDF");
      downloadAsPDFButton.setWidth("50%");
      downloadAsPDFButton.addClickHandler(new ClickHandler() {
      @Override
      public void onClick(ClickEvent event) {
      final DSRequest requestProperties = new DSRequest();
      requestProperties.setExportDisplay(ExportDisplay.DOWNLOAD);
      RPCManager.exportContent(theLayout);
      }
      });

      final HLayout buttonsLayout = new HLayout();
      buttonsLayout.setMargin(5);
      buttonsLayout.setWidth100();
      buttonsLayout.setMembersMargin(20);
      buttonsLayout.addMember(viewAsPDFButton);
      buttonsLayout.addMember(downloadAsPDFButton);

      theLayout.setWidth100();
      theLayout.setHeight(600);
      theLayout.setMembersMargin(20);
      theLayout.addMember(grid);
      theLayout.addMember(chart);
      theLayout.addMember(buttonsLayout);
      theLayout.draw();
      }

      Attached Files

      Comment


        #4
        We just tried the exact Showcase example you linked to and received a chart of the expected size: approximately the width of the grid.

        If you receive something different from the online sample, your PDF view may be flawed.

        If the online sample includes a right-sized chart but your local deploy of the Showcase doesn't, you may have replaced some of the included .jars that are related to PDF rendering (see Java Module Dependencies in the "docs" package in the JavaDocs) with other .jars that are different versions, and have bugs.

        Comment


          #5
          Thanks Team, The Problem was the Jars only now pdf is coming with full size chart. Thanks for quick guidance. :)

          Comment

          Working...
          X