---
name: charts
description: Build and debug JasperReports charts, including the charts module dependency, chart types, category, pie and XY datasets, series and category expressions, increment and reset settings, evaluation time, customizers and rendering checks across versions. Use when a chart is missing, fails to compile or load, shows wrong or partial values, or must match report totals; not for drawing static lines or shapes, or for tables and crosstabs.
---
# Build charts
## Establish the chart contract
Identify the exact engine, charts module, JFreeChart and Java versions, the chart type, which rows feed it (main data or a sub-dataset), the series, categories and values, how duplicates and nulls must be combined, which printed totals the chart must match, and the export formats. Ask for a small input table and the expected value of each bar or slice instead of guessing.
## Workflow
1. Add the charts module. In JasperReports 7.x charts live in `net.sf.jasperreports:jasperreports-charts`, at the same version as the engine, which brings JFreeChart. Without it, compiling a JRXML with a chart fails with `Could not resolve type id 'chart' as a subtype of ...JRChild`, and loading a `.jasper` compiled with the module fails with `Class net.sf.jasperreports.charts.base.JRBaseChart is not visible to deserialization.` Treat both messages as a missing runtime dependency, not as a template error.
2. Write 7.x chart syntax. Use `<element kind="chart" chartType="bar">` (or `pie`, `line`, `area`, `xyLine` and others), a `<dataset kind="category">` (or `pie`, `xy`, `timeSeries`) with one `<series>` per series and `seriesExpression`, `categoryExpression` and `valueExpression`, and a `<plot/>`. Convert 6.x `<barChart><chart>...<categoryDataset>` forms instead of mixing syntaxes.
3. Aggregate before plotting. A category dataset keeps one value per series and category: in the tested 7.1.1 runtime, a second row for the same pair replaces the first, so the chart drops values that the report total includes. Pre-aggregate in the query, or sort by the keys, add a group per pair with a `Sum` variable (`resetType="Group"`) and set `incrementType="Group"` with that `incrementGroup` on the dataset, using the variable as the value.
4. Place and time the chart. A chart in the summary with `evaluationTime="Report"` sees every row; a chart in a group band needs a dataset `resetType`/`resetGroup` and an `evaluationTime="Group"` for that group. Use a sub-dataset with a fresh data source for data that is not the main report data.
5. Handle nulls and empty data deliberately. A null value is kept as missing, not as zero; decide whether to filter nulls or replace them with zero, and what an empty chart should show.
6. Customize through `customizerClass` implementing `net.sf.jasperreports.charts.JRChartCustomizer`, rather than post-processing images. The same hook lets tests capture the JFreeChart and read its dataset.
## Validate and deliver
Fill with distinct series and categories, a duplicated pair, a null value and empty input, and assert each dataset value and that the chart values add up to the printed totals, for example through a test customizer that captures the dataset. Test the missing-module failure in an environment or class loader without `jasperreports-charts`. When upgrading the engine, charts module or JFreeChart, compare dataset values first, then inspect the rendered charts of affected reports side by side. State commands and results, and label any chart type, export or visual comparison you could not run as unverified.
## Sources
- [Sample reference](https://jasperreports.sourceforge.net/sample.reference/README.html)
- [Schema reference](https://jasperreports.sourceforge.net/schema.reference.html)
- [API](https://jasperreports.sourceforge.net/api/index.html)
— ‹guest · 2026-11-29› —
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.