Skip to content

jx:chart

jx:chart embeds an Excel chart in the output workbook. Define the chart type, data series, and placement in the template — XLFill handles the data range sizing based on actual output rows.

jx:chart(lastCell="H15" type="bar" title="Revenue by Region" catRange="A2:A2" valRange="B2:B2")
jx:chart(lastCell="H15" type="line" title="Monthly Trend" catRange="A2:A2" valRange="B2:B2,C2:C2" seriesNames="Revenue,Costs")
jx:chart(lastCell="F12" type="pie" title="Market Share" catRange="A2:A2" valRange="B2:B2")
AttributeRequiredDescription
lastCellYesBottom-right cell of the chart placement area
typeYesChart type: bar, col, line, pie, doughnut, area, scatter, radar
titleNoChart title text
catRangeYesCategory axis data range (template-relative, auto-expanded)
valRangeYesValue data range(s), comma-separated for multiple series
seriesNamesNoComma-separated names for each data series
styleNoChart style index (1-48, matching Excel’s chart styles)
widthNoChart width in EMUs or cells
heightNoChart height in EMUs or cells
legendPositionNoLegend position: bottom, left, right, top, none

Use it when your report data needs visual representation alongside the numbers:

  • Bar charts for comparing categories (revenue by region, sales by product)
  • Line charts for time series (monthly trends, growth rates)
  • Pie charts for composition (market share, budget allocation)
  • Multi-series charts for correlation (revenue vs. costs over time)
Cell A1 comment:
jx:area(lastCell="H20")
jx:each(items="regions" var="r" lastCell="B1")
Cell E1 comment:
jx:chart(lastCell="H15" type="bar" title="Revenue by Region" catRange="A2:A2" valRange="B2:B2")

Cell A1: ${r.Name}, Cell B1: ${r.Revenue}

XLFill expands the data rows, then sizes the chart’s data ranges to cover all output rows. If you have 10 regions, the chart references A2:A11 and B2:B11 automatically.

jx:chart(lastCell="H18" type="line" title="Revenue vs Costs" catRange="A2:A2" valRange="B2:B2,C2:C2" seriesNames="Revenue,Costs" legendPosition="bottom")

Two series plotted on the same chart. The seriesNames attribute labels them in the legend.

jx:chart(lastCell="F12" type="pie" title="Market Share" catRange="A2:A2" valRange="B2:B2")

Clean pie chart showing the proportion of each category. Excel handles the percentage labels.

The chart is anchored to the cell containing the command and extends to lastCell. Choose an area to the right of or below your data table so the chart doesn’t overlap with data rows. The chart floats as an overlay — it doesn’t shift when rows expand.

jx:chart uses deferred execution. Charts are defined during processing and created after all data rows are written. This is essential because the chart’s data ranges must reference the final output rows, not the template rows.

Add compact in-cell visualizations with sparklines:

jx:sparkline →