> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nika.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# CSV chart report

> T2 chain · data → picture: paste the spreadsheet, get the slide. Offline, deterministic, zero model calls.

> **T2 chain · data → picture**: `nika:read` loads the CSV,
> `nika:convert` types it into rows, `nika:jq` aggregates by region,
> `nika:chart` renders the bar chart as a real image, and `nika:write`
> assembles the markdown report around it. Six tasks, zero model
> calls: the whole pipeline is deterministic data plumbing.

## The job

The Monday deck needs one chart and one table, and the ritual is
always the same: open the sheet, pivot, screenshot, paste. This
workflow replaces the ritual with a file — drop the CSV, run once,
and the report (chart image + aggregate table) is on disk, identical
every time the data is identical.

## The shape

```mermaid theme={"system"}
flowchart LR
  raw["raw · nika:read"]:::invoke
  rows["rows · nika:convert"]:::invoke
  by_region["by_region · nika:jq"]:::invoke
  chart["chart · nika:chart"]:::invoke
  rows_md["rows_md · nika:jq"]:::invoke
  report["report · nika:write"]:::invoke
  raw --> rows
  rows --> by_region
  by_region --> chart
  by_region --> rows_md
  rows_md --> report
  chart -.->|success| report
  classDef invoke fill:#22d3ee22,stroke:#22d3ee,color:#22d3ee
```

## The file

```yaml csv-chart-report.nika theme={"system"}
nika: csv-chart-report

const:
  sales_csv: "examples/fixtures/sales.csv" # columns · region,revenue (revenue a plain number)

permits:
  exec: false
  tools: ["nika:chart", "nika:convert", "nika:jq", "nika:read", "nika:write"]
  fs:
    # The one CSV this reads, named exactly. `data/**` would have granted a
    # whole tree to a workflow that opens a single file.
    read: ["examples/fixtures/sales.csv"]
    # Two artifacts land here — the SVG and the report page. `**` because the
    # chart and the report are written by two different builtins into the
    # same tree, and both are covered by one honest entry.
    write: ["out/**"]

tasks:
  raw:
    invoke:
      tool: "nika:read"
      args: { path: "${{ const.sales_csv }}" }

  rows:
    with:
      raw: ${{ tasks.raw.output }}
    invoke:
      tool: "nika:convert"
      args:
        input: "${{ with.raw }}"
        from: csv
        to: json
        has_header: true

  # Sum revenue per region · a deterministic reduce, no model.
  by_region:
    with:
      rows: ${{ tasks.rows.output }}
    invoke:
      tool: "nika:jq"
      args:
        input: "${{ with.rows }}"
        expression: 'group_by(.region) | map({ region: .[0].region, revenue: (map(.revenue | tonumber) | add) })'

  # The picture · one SVG, its sha lands in the trace.
  chart:
    with:
      by_region: ${{ tasks.by_region.output }}
    invoke:
      tool: "nika:chart"
      args:
        data: "${{ with.by_region }}"
        semantics: { region: category, revenue: usd }
        chart: { type: bar, x: region, y: revenue, title: "Revenue by region" }
        out: out/revenue-by-region.svg

  # The rows as MARKDOWN · a report renders lines, never a JSON blob
  # (region names are user data — the esc guards a `|` in them).
  rows_md:
    with:
      by_region: ${{ tasks.by_region.output }}
    invoke:
      tool: "nika:jq"
      args:
        input: "${{ with.by_region }}"
        expression: >-
          def esc: tostring | gsub("\\|"; "\\|") | gsub("\n"; " ");
          map("| \(.region | esc) | \(.revenue) |") | join("\n")

  # The page · the report references the picture beside it.
  report:
    with:
      rows_md: ${{ tasks.rows_md.output }}
    after:
      chart: success
    invoke:
      tool: "nika:write"
      args:
        path: out/revenue-report.md
        content: |
          # Revenue by region

          ![Revenue by region](revenue-by-region.svg)

          | region | revenue |
          | --- | --- |
          ${{ with.rows_md }}

          *Generated offline by [nika](https://nika.sh) · the chart's sha is in the run trace (`nika trace verify`).*

outputs:
  by_region:
    value: ${{ tasks.by_region.output }}
    description: "Per-region revenue totals · the chart + report render from this"
```

## What this file teaches

* **`nika:convert` is the typed seam** — CSV text becomes structured
  rows once, at one task, and everything downstream works on data,
  not strings. The jq aggregation reads fields, never re-parses.
* **A chart is an artifact, not a side effect** — `nika:chart` returns
  a rendered image the report links by path. Re-running with the same
  CSV produces the same bytes: the chart can live in git, and a diff
  on it means the *data* moved.
* **No model, no bill, no network** — `nika check` shows an empty cost
  interval, and the run works on a plane. Determinism is the feature:
  this is the workflow you trust in a cron.

## Run it

> [!NOTE]
>
> **What it needs:** The sample sales CSV. No model, no key, no network.

**1. Rehearse it**

```bash theme={"system"}
nika try csv-chart-report
```

The sample files come with it and nothing is written in your folder.

**2. Get your own copy**

Save the file above as `csv-chart-report.nika` in a new folder, then download the sample it reads:

```bash theme={"system"}
FIXTURES=https://raw.githubusercontent.com/supernovae-st/nika/v0.124.3/crates/nika-pack/pack/examples/fixtures
mkdir -p examples/fixtures
curl -fsSLo examples/fixtures/sales.csv "$FIXTURES/sales.csv"
```

**3. Check it, then run it**

```bash theme={"system"}
nika check csv-chart-report.nika
nika run csv-chart-report.nika
```

The run writes `out/revenue-report.md` and the chart beside it, `out/revenue-by-region.svg`.

To chart your own export (columns `region,revenue`), point `const.sales_csv` at it and move the read permit with it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.