I'm trying to generate a Jasper Report using DynamicJasper which is just a chart, with no table appearing above it. There doesn't seem to be a method for hiding a column or for suppressing the table. What are my options for generating just a chart? I would be open to a solution that does not use DynamicJasper, just the JasperReports java API.
public void go() throws ColumnBuilderException, ClassNotFoundException, JRException {
super();
final AbstractColumn areas = ColumnBuilder.getNew()
.setColumnProperty("area", String.class.getName())
.setTitle("Area")
.setWidth(30)
.build();
final AbstractColumn exercises = ColumnBuilder.getNew()
.setColumnProperty("exercises", Integer.class.getName())
.setTitle("Exercises")
.setWidth(30)
.build();
final DynamicReportBuilder reportBuilder = new DynamicReportBuilder();
reportBuilder.addColumn(areas);
reportBuilder.addColumn(exercises);
reportBuilder.setUseFullPageWidth(true);
final GroupBuilder groupBuilder = new GroupBuilder();
groupBuilder.setCriteriaColumn((PropertyColumn) areas);
groupBuilder.setGroupLayout(GroupLayout.EMPTY);
final DJGroup group = groupBuilder.build();
reportBuilder.addGroup(group);
reportBuilder.addChart(this.chart((PropertyColumn) areas, exercises));
final DynamicReport dynamicReport = reportBuilder.build();
final JasperPrint jasperPrint =
DynamicJasperHelper.generateJasperPrint(
dynamicReport,
new ClassicLayoutManager(),
new JRBeanCollectionDataSource(this.getData()));
/* PDF */
final JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("/tmp/my.pdf"));
exporter.exportReport();
}
Instead of
addColumn
useaddField
. Thanks to Petter Friberg for this commentIf
DynamicJasper
is no must for you, you could try it with the DynamicReports library.I only did some few tests with both, but I found the
DynamicReports
much more easier to use.Example code from my tests back then, a report with chart only (or uncomment the
.columns
section to get the columns back):For more examples have a look here: dynamicreports.org examples
I know this is an old question, but I wanted to share my solution after I spent hours trying to figure out a solution to this.
Unfortunately, the above 2 answers did not work for me while using DynamicJasper 5.1.0. DynamicReports seems to be no longer maintained and the link is broken, and simply using addField instead of addColumn resulted in the unhelpful "duplicate declaration of parameter: dataset_null_chart" error - which seems to be related to having duplicate charts despite the fact that I was only using a single chart. (That being said, I'd love to hear if/how someone overcame these issues using DynamicJasper 5.1.x)
So I came up with the following solution - create a
LayoutManager
that does not render the table:Then use this when you generate your
JasperPrint
object:This worked perfectly for my simple scenario of creating a stacked bar chart without a table. I haven't tried more complex reports while hiding the table, so I don't know if this will work in every situation, but it should work in the scenario you asked about, at least in DynamicJasper 5.1.0.