Create dynamic reports in LibreOffice
Create pie charts in ODT documents in LibreOffice
The dataset below is used in a chart that represents the quantity of cheese purchased by french households in 2019.
Step 1: Prepare JSON data
Group values by cheese types using the following dataset:
Data
Step 2: Create a new ODT
template in LibreOffice
ODT
template in LibreOfficeClick the Home tab > Chart button. A column chart appears. Change the chart format by clicking the chart type button from the chart toolbar.
Step 3: Edit chart values
Insert the data dynamically using a loop
and the bindChart
formatter: Click Data Table from the chart toolbar. A popup appears to edit chart values.
The following is not different than Microsoft Word. It's not possible to insert tag {d.value}
inside table cells, except in the first column Categories
.
So you write the category name, then add bindChart
tags. The {bindChart}
formatter is used to bind a variable to a reference tag in the table cell, i.e., "the value X
in the chart must be replaced by the tag Y
."
Screenshot explanations
jn the first cell, the following expression is written:
{d.cheeses[i].type} {bindChart(3)=d.cheeses[i].purchasedTonnes}
the cheese type is printed with
{d.cheeses[i].type}
, thenbindChart
is used to bind the variabled.cheeses[i].purchasedTonnes
to the cell that has the value3
this means: the
purchasedTonnes
value is printed instead of3
in the first cell of the second row, the expression
{d.cheeses[i+1].type} {bindChart(4)=d.cheeses[i+1].purchasedTonnes}
is writtenthe
bindChart
replaces the4
value by thed.cheeses[i+1].purchasedTonnes
variable
Step 4: Generate the report
Generate the PDF
report, and the pie chart is automatically filled.
Last updated