こんにちは、itextpdf-5.1.0.jar を使用して、テーブル (このテーブルの値は入力画面の開始日と終了日に基づいてデータベースから取得されます) と上記のテーブルの値の棒グラフを表示します。
問題は、テーブルの下に棒グラフを配置したいことです。データベースからフェッチする値は、開始日と終了日によって異なる場合があります。現在、いくつかの静的な値 (234,567) を指定して、テーブルと棒グラフを配置しています。多数の値テーブルの値と棒グラフが上書きされています。テーブルと棒グラフを動的に配置する他の方法はありますか?
Document document = new Document(PageSize.A4_LANDSCAPE, 10, 10, 10, 10);
document.open();
document.add(new Paragraph("Batch Report:", FontFactory.getFont(FontFactory.COURIER, 10, Font.BOLD, new CMYKColor(255, 255, 255, 255))));
Paragraph paragraph1 = new Paragraph();
paragraph1.setSpacingBefore(4);
document.add(paragraph1);
PdfPTable table = new PdfPTable(5);
table.setWidthPercentage(100);
PdfPCell c1;
for (BoardBean bean : listHeader) {
addColumn(bean.getID(),c1,table,myColor,btableheadercolor);
}
テーブルに列の値を追加する
private void addColumn(String text,PdfPCell c1,PdfPTable dataTable,BaseColor myColor,BaseColor btablecolumncolor) {
try {
final Font tabletdcolor = new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL, BaseColor.BLACK);
c1 = new PdfPCell(new Paragraph(text, tabletdcolor));
cellStyle(c1, myColor, btablecolumncolor);
dataTable.addCell(c1);
} catch (Exception ex) {
ex.printStackTrace();
}
}
棒グラフの生成
JFreeChart reportBarChart = genBatchReportBarChart(listHeader);
PdfTemplate reportTemplate = contentByte.createTemplate(280, 230);
Graphics2D reportGraphics = reportTemplate.createGraphics(280, 230, new DefaultFontMapper());
Rectangle2D reportRectangle = new Rectangle2D.Double(0, 0, 280, 230);
reportBarChart.draw(reportGraphics, reportRectangle);
reportGraphics.dispose();
contentByte.addTemplate(reportTemplate, 10, height+150);
上記のコードでは、棒グラフの位置を修正しています。値の数が少ない場合は問題ありませんが、数値が大きい場合は棒グラフがテーブルの値を上書きしています。テーブルの値に応じて、棒グラフをどのように配置する必要がありますか私はそれを達成することができます。