private void build() {
    FontBuilder boldFont = stl.fontArialBold().setFontSize(12);

    TextColumnBuilder<Integer> xColumn = col.column("X", "x", type.integerType());
    TextColumnBuilder<Integer> yColumn = col.column("Y", "y", type.integerType());
    TextColumnBuilder<Integer> zColumn = col.column("Z", "z", type.integerType());

    try {
      report()
          .setTemplate(Templates.reportTemplate)
          .columns(xColumn, yColumn, zColumn)
          .title(Templates.createTitleComponent("XYBlockChart"))
          .summary(
              cht.xyBlockChart(0, 5, Color.WHITE)
                  .setTitle("XY block chart")
                  .setTitleFont(boldFont)
                  .setBlockAnchor(RectangleAnchor.BOTTOM_LEFT)
                  .paintScales(
                      cht.paintScale("Value 1", 1, Color.RED),
                      cht.paintScale("Value 2", 2, Color.GREEN),
                      cht.paintScale("Value 3", 3, Color.BLUE))
                  .setXValue(xColumn)
                  .series(cht.xyzSerie().setYValue(yColumn).setZValue(zColumn))
                  .setXAxisFormat(cht.axisFormat().setLabel("X"))
                  .setYAxisFormat(cht.axisFormat().setLabel("Y")))
          .pageFooter(Templates.footerComponent)
          .setDataSource(createDataSource())
          .show();
    } catch (DRException e) {
      e.printStackTrace();
    }
  }
  public void build() {
    FontBuilder boldFont = stl.fontArialBold().setFontSize(12);

    TextColumnBuilder<String> staffColumn = col.column("Staff", "staff", type.stringType());
    TextColumnBuilder<Integer> absentColumn =
        col.column("Absent days", "absent", type.integerType());
    TextColumnBuilder<Integer> presentColumn =
        col.column("Present days", "present", type.integerType());
    Orientation orientation = Orientation.VERTICAL;

    try {
      report()
          .setTemplate(Templates.reportTemplate)
          .columns(staffColumn, absentColumn, presentColumn)
          .title(Templates.createTitleComponent("Staff LineChart"))
          .summary(
              cht.lineChart()
                  //					cht.stackedBarChart()
                  .setTitle("Staff Attendance Report")
                  .setTitleFont(boldFont)
                  .setCategory(staffColumn)
                  .series(cht.serie(absentColumn), cht.serie(presentColumn))
                  .setCategoryAxisFormat(cht.axisFormat().setLabel("Staff")))
          .pageFooter(Templates.footerComponent)
          .setDataSource(createDataSource())
          .show();
    } catch (DRException e) {
      e.printStackTrace();
    }
  }
  private void build() {
    TextColumnBuilder<String> itemColumn = col.column("Item", "item", type.stringType());
    TextColumnBuilder<Integer> stock1Column = col.column("Stock 1", "stock1", type.integerType());
    TextColumnBuilder<Integer> stock2Column = col.column("Stock 2", "stock2", type.integerType());
    TextColumnBuilder<Integer> stock3Column = col.column("Stock 3", "stock3", type.integerType());

    BarChartBuilder barChart =
        cht.barChart()
            .setShowPercentages(true)
            .setShowValues(true)
            .setPercentValuePattern("#,##0")
            .setCategory(itemColumn)
            .series(cht.serie(stock1Column), cht.serie(stock2Column), cht.serie(stock3Column));
    StackedBarChartBuilder stackedBarChart =
        cht.stackedBarChart()
            .setShowPercentages(true)
            .setShowValues(true)
            .setCategory(itemColumn)
            .series(cht.serie(stock1Column), cht.serie(stock2Column), cht.serie(stock3Column));
    LineChartBuilder lineChart =
        cht.lineChart()
            .setShowPercentages(true)
            .setShowValues(true)
            .setCategory(itemColumn)
            .series(cht.serie(stock1Column), cht.serie(stock2Column), cht.serie(stock3Column));
    AreaChartBuilder areaChart =
        cht.areaChart()
            .setShowPercentages(true)
            .setShowValues(true)
            .setCategory(itemColumn)
            .series(cht.serie(stock1Column), cht.serie(stock2Column), cht.serie(stock3Column));
    StackedBar3DChartBuilder stackedBar3DChart =
        cht.stackedBar3DChart()
            .setShowPercentages(true)
            .setShowValues(true)
            .setCategory(itemColumn)
            .series(cht.serie(stock1Column), cht.serie(stock2Column), cht.serie(stock3Column));
    PieChartBuilder pieChart =
        cht.pieChart()
            .setShowPercentages(true)
            .setShowValues(true)
            .setKey(itemColumn)
            .series(cht.serie(stock1Column));

    try {
      report()
          .setTemplate(Templates.reportTemplate)
          .columns(itemColumn, stock1Column, stock2Column, stock3Column)
          .title(Templates.createTitleComponent("ChartShowPercentages"))
          .summary(
              cmp.horizontalList(barChart, stackedBarChart),
              cmp.horizontalList(lineChart, areaChart),
              cmp.horizontalList(stackedBar3DChart, pieChart))
          .pageFooter(Templates.footerComponent)
          .setDataSource(createDataSource())
          .show();
    } catch (DRException e) {
      e.printStackTrace();
    }
  }
  private void build() {
    FontBuilder boldFont = stl.fontArialBold().setFontSize(12);

    TextColumnBuilder<String> yearColumn = col.column("Year", "year", type.stringType());
    TextColumnBuilder<String> quarterColumn = col.column("Quarter", "quarter", type.stringType());
    TextColumnBuilder<Integer> stock1Column = col.column("Stock 1", "stock1", type.integerType());
    TextColumnBuilder<Integer> stock2Column = col.column("Stock 2", "stock2", type.integerType());
    TextColumnBuilder<Integer> stock3Column = col.column("Stock 3", "stock3", type.integerType());

    try {
      report()
          .setTemplate(Templates.reportTemplate)
          .columns(yearColumn, quarterColumn, stock1Column, stock2Column, stock3Column)
          .title(Templates.createTitleComponent("GroupedStackedBarChart"))
          .summary(
              cht.groupedStackedBarChart()
                  .setTitle("Grouped stacked bar chart")
                  .setTitleFont(boldFont)
                  .setCategory(yearColumn)
                  .series(
                      cht.groupedSerie(stock1Column).setGroup(quarterColumn),
                      cht.groupedSerie(stock2Column).setGroup(quarterColumn),
                      cht.groupedSerie(stock3Column).setGroup(quarterColumn)))
          .pageFooter(Templates.footerComponent)
          .setDataSource(createDataSource())
          .show();
    } catch (DRException e) {
      e.printStackTrace();
    }
  }
 public static void printGivingStatement(String lastName, String firstName) {
   final JasperReportBuilder statement = createGivingStatement(lastName, firstName);
   try {
     statement.print(true);
   } catch (DRException e) {
     e.printStackTrace();
   }
 }
 public static void main(String[] args) {
   DynamicReportDesign design = new DynamicReportDesign();
   try {
     JasperReportBuilder report = design.build();
     report.show();
   } catch (DRException e) {
     e.printStackTrace();
   }
 }
 public static void writeGivingStatement(String lastName, String firstName, File outputFile)
     throws IOException {
   final FileOutputStream os = new FileOutputStream(outputFile);
   try {
     final JasperReportBuilder statement = createGivingStatement(lastName, firstName);
     statement.toXlsx(os);
   } catch (DRException e) {
     JOptionPane.showMessageDialog(null, "Exception occurred writing report: " + e.getMessage());
     e.printStackTrace();
   } finally {
     os.flush();
     os.close();
   }
 }
 private void build() {
   try {
     report()
         .setTemplate(Templates.reportTemplate)
         .columns(
             col.column("Item", "item", type.stringType()),
             col.column("Quantity", "quantity", type.integerType()),
             col.column("Comments", "comments", type.listType()))
         .title(Templates.createTitleComponent("ColumnListDataType"))
         .pageFooter(Templates.footerComponent)
         .setDataSource(createDataSource())
         .show();
   } catch (DRException e) {
     e.printStackTrace();
   }
 }
示例#9
0
  private void build() {
    ComponentBuilder<?, ?> cardComponent = createCardComponent();
    HorizontalListBuilder cards = cmp.horizontalFlowList();
    for (int i = 0; i < 10; i++) {
      cards.add(cardComponent);
    }

    try {
      report()
          .setTemplate(Templates.reportTemplate)
          .setTextStyle(stl.style())
          .setPageFormat(PageType.A5)
          .title(Templates.createTitleComponent("Card"), cards)
          .show();
    } catch (DRException e) {
      e.printStackTrace();
    }
  }
示例#10
0
  private void build() {
    try {
      JasperHtmlExporterBuilder htmlExporter =
          export
              .htmlExporter("c:/report.html")
              .setImagesDirName("c:/images")
              .setOutputImagesToDir(true);

      report()
          .setTemplate(Templates.reportTemplate)
          .columns(
              col.column("Item", "item", type.stringType()),
              col.column("Quantity", "quantity", type.integerType()),
              col.column("Unit price", "unitprice", type.bigDecimalType()))
          .title(Templates.createTitleComponent("HtmlReport"))
          .pageFooter(Templates.footerComponent)
          .setDataSource(createDataSource())
          .toHtml(htmlExporter);
    } catch (DRException e) {
      e.printStackTrace();
    }
  }
  private void build() {
    FieldBuilder<Date> dateField = field("date", type.dateType());
    FieldBuilder<Integer> stock1Field = field("stock1", type.integerType());
    FieldBuilder<Integer> stock2Field = field("stock2", type.integerType());

    CategoryChartSerieBuilder stock1Serie = cht.serie(stock1Field).setLabel("Stock1");
    CategoryChartSerieBuilder stock2Serie = cht.serie(stock2Field).setLabel("Stock2");

    LineChartBuilder chart1 =
        cht.lineChart()
            .setCategory(new CategoryExpression())
            .series(stock1Serie)
            .setValueAxisFormat(cht.axisFormat().setLabel("Stock1"));

    BarChartBuilder chart2 =
        cht.barChart()
            .setCategory(new CategoryExpression())
            .series(stock2Serie)
            .setValueAxisFormat(cht.axisFormat().setLabel("Stock2"));

    try {
      report()
          .setTemplate(Templates.reportTemplate)
          .fields(dateField)
          .title(
              Templates.createTitleComponent("MultiAxisChart"),
              cht.multiAxisChart(chart1, chart2),
              cht.multiAxisChart()
                  .addChart(chart1, AxisPosition.LEFT_OR_TOP)
                  .addChart(chart2, AxisPosition.RIGHT_OR_BOTTOM))
          .pageFooter(Templates.footerComponent)
          .setDataSource(createDataSource())
          .show();
    } catch (DRException e) {
      e.printStackTrace();
    }
  }
  private void build() {
    boldCenteredStyle = stl.style().bold().setHorizontalAlignment(HorizontalAlignment.CENTER);
    StyleBuilder backgroundStyle =
        stl.style(boldCenteredStyle)
            .setVerticalAlignment(VerticalAlignment.MIDDLE)
            .setRotation(Rotation.LEFT);

    TextColumnBuilder<String> column1 = col.column("Column1", "column1", type.stringType());
    TextColumnBuilder<String> column2 = col.column("Column2", "column2", type.stringType());
    ColumnGroupBuilder columnGroup = grp.group(column1);

    try {
      report() // create new report design
          .setPageColumnsPerPage(2)
          .columns(column1, column2)
          .groupBy(columnGroup)

          // bands
          .title(createTextField("This is a title band"))
          .pageHeader(createTextField("This is a page header band"))
          .pageFooter(createTextField("This is a page footer band"))
          .columnHeader(createTextField("This is a column header band"))
          .columnFooter(createTextField("This is a column footer band"))
          .lastPageFooter(createTextField("This is a last page footer band"))
          .summary(createTextField("This is a summary band"))
          // .detailHeader(createTextField("This is a detail header band"))
          // .detailFooter(createTextField("This is a detail footer band"))
          .groupHeader(columnGroup, createTextField("This is a group header band"))
          .groupFooter(columnGroup, createTextField("This is a group footer band"))
          .background(
              createTextField("This is a background band").setHeight(800).setStyle(backgroundStyle))
          .setDataSource(createDataSource()) // set datasource
          .show(); // create and show report
    } catch (DRException e) {
      e.printStackTrace();
    }
  }
  @Test
  public void test() {
    try {
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      concatenatedReport.toCsv(bos);
      Assert.assertEquals(
          "concatenated report ", "text1\n1\ntext2\n1\ntext3\n1\n", new String(bos.toByteArray()));

      concatenatedReport.continuousPageNumbering();
      bos = new ByteArrayOutputStream();
      concatenatedReport.toCsv(bos);
      Assert.assertEquals(
          "concatenated report ", "text1\n1\ntext2\n2\ntext3\n3\n", new String(bos.toByteArray()));

      concatenatedReport.setContinuousPageNumbering(false);
      bos = new ByteArrayOutputStream();
      concatenatedReport.toCsv(bos);
      Assert.assertEquals(
          "concatenated report ", "text1\n1\ntext2\n1\ntext3\n1\n", new String(bos.toByteArray()));
    } catch (DRException e) {
      e.printStackTrace();
      Assert.fail(e.getMessage());
    }
  }
  private void build() {

    try {
      report()
          .setTemplate(Templates.reportTemplate)
          .ignorePageWidth()
          .columns(
              col.column("ID", "id", type.integerType()),
              col.column("Item", "item", type.stringType()),
              col.column("Quantity", "quantity", type.integerType()),
              col.column("Unit price", "unitprice", type.bigDecimalType()),
              col.column("Order date", "orderdate", type.dateType()),
              col.column("Order date", "orderdate", type.dateYearToFractionType()),
              col.column("Order year", "orderdate", type.dateYearType()),
              col.column("Order month", "orderdate", type.dateMonthType()),
              col.column("Order day", "orderdate", type.dateDayType()))
          .title(Templates.createTitleComponent("DynamicPageWidth"))
          .pageFooter(Templates.footerComponent)
          .setDataSource(createDataSource())
          .show();
    } catch (DRException e) {
      e.printStackTrace();
    }
  }