ComposeIt LogoComposeIt
Advanced Concepts

Charts, Formulas & LaTeX

End-to-end guide to building analytical reports with dynamic chart visualizations, data-formula reshaping (MAP), hidden calculation layers, custom variable inputs, grouped tables, and LaTeX mathematical typesetting.

Complex reporting often requires transforming raw database or webhook records into clean visual presentations. In this guide, we walk through how to build an automated Quarterly Performance & Data Analysis Report combining dynamic charts, computed formulas, hidden calculation layers, structured tables, and mathematical typesetting with LaTeX.

Analytical Report with Charts, Formulas, and LaTeX

1. Scenario: Quarterly Performance Report

Consider a reporting scenario where your backend or webhook sends raw operational metrics for quarterly sales across multiple product categories:

{
  "reportTitle": "Q3 Executive Performance Report",
  "company": "Acme Innovations Inc.",
  "reportingPeriod": "Q3 2024",
  "quarterlyData": [
    {
      "quarter": "Q1",
      "revenue": 142000,
      "expenses": 98000,
      "unitsSold": 1250,
      "satisfaction": 88
    },
    {
      "quarter": "Q2",
      "revenue": 178000,
      "expenses": 112000,
      "unitsSold": 1640,
      "satisfaction": 91
    },
    {
      "quarter": "Q3",
      "revenue": 215000,
      "expenses": 129000,
      "unitsSold": 2080,
      "satisfaction": 94
    },
    {
      "quarter": "Q4",
      "revenue": 196000,
      "expenses": 121000,
      "unitsSold": 1820,
      "satisfaction": 89
    }
  ],
  "campaigns": [
    { "name": "Summer Boost", "spend": 12000, "conversions": 480, "roi": 4.2 },
    {
      "name": "Product Launch",
      "spend": 28000,
      "conversions": 940,
      "roi": 3.8
    },
    { "name": "Retargeting", "spend": 8500, "conversions": 390, "roi": 5.1 }
  ]
}

Our goal is to render:

  1. A Bar & Line Chart comparing revenue vs. expenses.
  2. A Scatter / Bubble Chart mapping campaign ad spend against conversions.
  3. A Summary Table grouping and totaling data.
  4. LaTeX Mathematical Blocks explaining analytical KPIs (such as Profit Margin and ROI formulas).

2. Dynamic Charts for Data Analysis

The Chart component renders server-side Chart.js charts directly as high-resolution images (<img>), ensuring instant rendering without needing client-side JavaScript.

Configuring Chart Traits and Types in Right Inspector

Adding a Chart Component

  1. Open the Block Manager on the left toolbar and drag a Chart block onto your canvas.
  2. In the Right Inspector Traits panel, configure the chart presentation:
    • Chart Type: Select bar, line, pie, doughnut, radar, polarArea, bubble, or scatter.
    • Title & Subtitle: Set running titles (e.g., "Quarterly Revenue vs Expenses").
    • Show Grid & Legend: Toggle visibility on or off.
    • Colors: Customize textColor, gridColor, and backgroundColor.
    • Labels: Set the X-axis categories (e.g., ["Q1", "Q2", "Q3", "Q4"] or bind to a data resolver).

3. Reshaping Data with Formulas (MAP)

Raw payload arrays rarely arrive in the exact numeric array or { x, y, r } point format that Chart.js expects. Instead of creating custom backend transformation scripts, use ComposeIt's built-in data-formula component and the MAP function.

The data-formula Component

The data-formula component accepts two primary traits:

  • formula (required): The expression string to compute.
  • variable (optional): The name of a variable on root to store the evaluated result (e.g., variable: "chartRevenueSeries").

When variable is defined, the result is saved into root.chartRevenueSeries, making it immediately accessible to charts, tables, or other formulas placed after it.

MAP(root.quarterlyData, 'revenue')
Editing Formulas in the Formula Modal

Copying from path selector

You can copy variables from the path selector avoiding the need for memorizing variable names and it provides the correct format that handles null values and accessing variables with spaces and special characters in their names eg root.["Total Revenue"].

Transforming Collections for Charts

The MAP(array, 'formula') function transforms array items into desired formats:

Example A: Extracting Numeric Arrays for Bar/Line Charts

For standard charts (bar, line), the dataset needs an array of numbers ([142000, 178000, 215000, 196000]):

Formula:  MAP(root.quarterlyData, 'revenue')
Variable: chartRevenue

Evaluates to: [142000, 178000, 215000, 196000]

Example B: Mapping Point Coordinates for Scatter Charts

Scatter charts require an array of { x, y } objects:

Formula:  MAP(root["campaigns"], '{ x: item.spend, y: item.conversions }')
Variable: scatterCampaignPoints

Evaluates to: [{ x: 12000, y: 480 }, { x: 28000, y: 940 }, { x: 8500, y: 390 }]

Example C: Mapping Coordinates & Radius for Bubble Charts

Bubble charts require an array of { x, y, r } objects:

Formula:  MAP(root["campaigns"], '{ x: item.spend, y: item.conversions, r: CEIL(item.roi * 3) }')
Variable: bubbleCampaignPoints

Evaluates to: [{ x: 12000, y: 480, r: 12.6 }, { x: 28000, y: 940, r: 11.4 }, { x: 8500, y: 390, r: 15.3 }]


4. Hiding Calculation Formulas from Layers

When you add a data-formula component to calculate intermediary variables (like chart data, tax totals, or statistical averages), the formula element itself should not appear visually on the printed PDF.

Hiding Formula Component in the Layer Manager

How to Hide Formula Elements

  1. Open the Layer Manager on the left sidebar (stacked layers icon).
  2. Locate the data-formula component in the layer tree.
  3. Click the Visibility icon (👁️ / EyeOff) next to the component.

How it works behind the scenes: Even when a component is hidden from the visual DOM, ComposeIt's template execution engine processes the calculation during document compilation. The variable is computed, stored in root[variable], and made available to subsequent components without printing any visible text.


5. Using Custom Variable Input in Charts

By default, the Cascading Path Selector in the trait editor navigates through static fields defined in your datasource schema.

However, when a variable was created dynamically at runtime by a data-formula (such as root.chartRevenue or root.bubbleCampaignPoints), it won't exist in the static schema picker.

Switching to Custom Variable Path Input

Binding Chart Data to a Dynamic Variable

  1. Select your Chart component and open the Datasets trait in the Right Inspector.
  2. Click on the dataset you wish to edit (e.g., "Dataset 1").
  3. In the dataset's Values section, click the Connect Datasource (🗄️) button.
  4. Instead of picking a field from the dropdown tree, enter your custom path directly in the path input:
    root.chartRevenue
    (Or for scatter/bubble points: root.scatterCampaignPoints)
  5. Save the modal. The chart dataset's data property is now bound to the formula-generated variable!
Chart with data

Editor Canvas Preview: When a chart dataset is bound to a dynamic variable resolver, the editor canvas automatically displays a notice: “Generated for editor preview” and shows sample data points so you can visually style the chart without needing a live render run.


6. Displaying Data with Grouped & Nested Tables

In analytical reports, visual charts should always be accompanied by structured summary tables.

Grouped and Nested Tables with Dynamic Data

Grouping Data in Tables

Grouping allows you to select a key to group data by that way the outer loop iterates over the grouped keys whilst exposing the items matching that key. You can further loop over these items creating complex nested layouts.

Grouped and Nested Tables with Dynamic Data

Calculating Group Totals

You can use formulas to calculate summary rows at the bottom of tables:

Total Revenue:  SUM(MAP(root.quarterlyData, 'revenue'))
Average Margin %: AVG(MAP(root.quarterlyData, '(revenue - expenses) / revenue * 100'))

7. Mathematical Typesetting with LaTeX (KaTeX)

Analytical reports often require showing the mathematical formulas behind key performance indicators. ComposeIt includes native support for LaTeX math expressions via KaTeX, ensuring crisp, vector-grade typography in rendered PDFs.

Typesetting Mathematical Formulas with KaTeX

Inserting Inline Math

To insert an inline formula inside any paragraph, use the data-math-inline:

"\text{ROI} = \frac{\text{Net Profit}}{\text{Total Investment}} \times 100\%"

Complex Formula Blocks

For multi-variable calculations, variance, or regression equations:

"\sigma = \sqrt{\frac{1}{N-1} \sum_{i=1}^{N} (x_i - \bar{x})^2}"

KaTeX equations render cleanly during server-side PDF generation with zero font blur, pixelation, or external image dependencies.


Summary Checklist

  • Chart Types: Select the appropriate chart type (bar, line, scatter, bubble).
  • Data Reshaping: Use data-formula with MAP to shape raw payloads into numeric arrays or { x, y, r } points.
  • Variable Assignment: Set the variable trait on the formula component to store results into root.
  • Layer Visibility: Hide intermediary data-formula elements in the Layer Manager.
  • Custom Path Input: Bind chart datasets directly to root.yourVariableName.
  • Accompanying Tables: Present granular data with grouped rows and formula sums.
  • LaTeX Formulas: Embed KaTeX math formulas to document statistical methodologies.
We use cookies to ensure you get the best experience on our website. For more information on how we use cookies, please see our privacy policy.