DRDataSource callDataSource = new DRDataSource("topK", "userId", "seatId", "usage");
DRDataSource textDataSource = new DRDataSource("topK", "userId", "seatId", "usage");
StyleBuilder borderStyle = Styles.style()
.setBorder(Styles.border(Styles.pen(1f, LineStyle.SOLID)))
.setHorizontalTextAlignment(HorizontalTextAlignment.CENTER);
var topK = col.column("Top k", "topK", type.integerType())
.setTitleStyle(stl.style(stl.fontTimesNewRomanBold()).setHorizontalTextAlignment(HorizontalTextAlignment.CENTER))
.setStyle(borderStyle);
var userId = col.column("User Id", "userId", type.longType())
.setStyle(borderStyle)
.setTitleStyle(stl.style(stl.fontTimesNewRomanBold()).setHorizontalTextAlignment(HorizontalTextAlignment.CENTER));
var seatId = col.column("Seat Id", "seatId", type.longType())
.setStyle(borderStyle)
.setTitleStyle(stl.style(stl.fontTimesNewRomanBold()).setHorizontalTextAlignment(HorizontalTextAlignment.CENTER));
var usage = col.column("Usage", "usage", type.integerType())
.setStyle(borderStyle)
.setTitleStyle(stl.style(stl.fontTimesNewRomanBold()).setHorizontalTextAlignment(HorizontalTextAlignment.CENTER));
JasperReportBuilder callMonthlySubReport = report()
.title(cmp.text("Top %d Usage - %s".formatted(LIMIT, CALL)).setStyle(stl.style(stl.fontTimesNewRoman().boldItalic())))
.setPageFormat(PageType.A4)
.columns(topK, userId, seatId, usage)
.setDataSource(callDataSource);
JasperReportBuilder textMonthlySubReport = report()
.title(cmp.text("Top %d Usage - %s".formatted(LIMIT, TEXT)).setStyle(stl.style(stl.fontTimesNewRoman().boldItalic())))
.setPageFormat(PageType.A4)
.columns(topK, userId, seatId, usage)
.setDataSource(textDataSource);
DRDataSource monthDataSource = new DRDataSource("month", "call", "text", "bill");
TextColumnBuilder<String> monthCol = col.column("Month", "month", type.stringType())
.setStyle(borderStyle)
.setTitleStyle(stl.style(stl.fontTimesNewRomanBold()).setHorizontalTextAlignment(HorizontalTextAlignment.CENTER));
TextColumnBuilder<Integer> callCol = col.column("Call", "call", type.integerType())
.setStyle(borderStyle)
.setTitleStyle(stl.style(stl.fontTimesNewRomanBold()).setHorizontalTextAlignment(HorizontalTextAlignment.CENTER));
TextColumnBuilder<Integer> textCol = col.column("Text", "text", type.integerType())
.setStyle(borderStyle)
.setTitleStyle(stl.style(stl.fontTimesNewRomanBold()).setHorizontalTextAlignment(HorizontalTextAlignment.CENTER));
TextColumnBuilder<BigDecimal> billCol = col.column("Bill", "bill", type.bigDecimalType())
.setStyle(borderStyle)
.setTitleStyle(stl.style(stl.fontTimesNewRomanBold()).setHorizontalTextAlignment(HorizontalTextAlignment.CENTER));
JasperReportBuilder sixMonthSubReport = report()
.title(cmp.text("Six Month Usage").setStyle(stl.style(stl.fontTimesNewRoman().boldItalic())))
.setPageFormat(PageType.A4)
.columns(monthCol, callCol, textCol, billCol)
.summary(
cht.lineChart()
.setCategory("month", String.class)
.series(cht.serie(callCol), cht.serie(textCol), cht.serie(billCol))
.setCategoryAxisFormat(cht.axisFormat().setLabel("Month"))
.setValueAxisFormat(cht.axisFormat().setLabel("Usage"))
)
.setDataSource(monthDataSource);
FileOutputStream outputStream = new FileOutputStream("/Users/moatable/Desktop/test.jpg");
report()
.pageHeader(cmp.text("Usage Report").setStyle(stl.style(stl.fontTimesNewRomanBold())))
.pageFooter(cmp.pageXofY())
.setPageFormat(PageType.A4)
.setPageMargin(margin(20))
.title(cmp.text("Monthly Usage Report - %s".formatted(month)).setStyle(stl
.style(stl.fontTimesNewRomanBold())))
.detail(cmp.verticalList(
cmp.subreport(callMonthlySubReport),
cmp.subreport(textMonthlySubReport),
cmp.subreport(sixMonthSubReport)
))
.toImage(outputStream, ImageType.JPG);
java.lang.IllegalArgumentException: Width (-1) and height (842) cannot be <= 0
at java.desktop/java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1016)
at java.desktop/java.awt.image.BufferedImage.<init>(BufferedImage.java:324)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toImage(JasperReportBuilder.java:548)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toImage(JasperReportBuilder.java:487)
at com.dialer.server.schedule.DailyUsageReportSchedule.main(DailyUsageReportSchedule.java:327)
I tried to use the above code to generate a report, but it told me that width=-1.These three reports can be exported normally. But when I combine them, I get an error. I debugged and found that the topage of the report was 0.
The length of the pages obtained here is 0,
if (toPage == null) {
toPage = jasperPrint.getPages().size();
}
I looked up this problem and didn’t find a solution.
New contributor
user26639686 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.