Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Charts and Graphs

Tips and techniques for producing charts from hledger data.

Built-in charts

New in hledger 1.99.6 (2.0 preview 6): hledger can show many reports as a chart. Add --chart to a balance, balancesheet, balancesheetequity, cashflow, incomestatement, register, aregister or holdings report; the activity command always shows one. A suitable kind of chart is chosen for the report: eg stacked bars per period for balance changes, lines for balances over time, a bar per account for a single period, or a bar per investment holding showing its cost basis and unrealised gain or loss.

In the terminal, the chart is drawn with text characters (in colour when supported):

$ hledger -f examples/sample.journal bal -Q expenses income --chart -w 50
Balance changes in 2008:

█ expenses:food  ▓ expenses:supplies
▒ income:gifts  ░ income:salary  ┃ Total

2008Q1  $-1  ┃░░░░░░░░░░░│
2008Q2   $1  ▒▒▒▒▒▒▒▒▒▒▒▒│███████████┃▓▓▓▓▓▓▓▓▓▓▓▓
2008Q3    0              ┃
2008Q4    0              ┃

With SVG output (eg -o chart.svg) it is a graphical chart; with HTML output, the report's table is shown below it; and with CSV, TSV or JSON output you get the chart's data. To see a graphical chart quickly, in your web browser, add --view:

$ hledger -f examples/bcexample.journal is -M -p 2013 cur:USD --chart --view

built-in chart of a monthly income statement

And to collect several reports and charts into one page, use the run command with --view, eg hledger run --view -- bs -M --chart -- is -M --chart. Here is a page of example charts made that way, from examples/bcexample.journal, each with its command and (under Report details) its report.

hledger-web shows the same charts, above the report on its All accounts, Balance sheet, Income statement, Cashflow statement and Holdings pages, and a balance over time chart on its register page. The c and d keys hide or show a page's chart and its table, and with several commodities, a legend chooses the one charted.

$ hledger-web -f examples/bcexample.journal

hledger-web's monthly income statement page, with its chart

For more, see Charts in the (dev) manual.

Charting tools built for hledger

Simplest first:

hledger-bar

hledger-bar (2023) is a bash script for making quick bar charts in the terminal. It's useful with hledger 1.x, or hledger 2.x previews up to 1.99.5.

$ hledger bar -v 1 -f $TIMELOG biz
2023-01	        15 +++++++++++++++
2023-02	        10 ++++++++++
2023-03	        20 ++++++++++++++++++++
2023-04	        12 ++++++++++++

hledger-plot

hledger-plot (2023) is a powerful chart-making addon you can install in PATH.

hledger-plot screenshot

hledger-lit

hledger-lit (2025) is a nice web UI that makes several kinds of chart.

hledger-sankeymatic

At https://sankeymatic.com you can make flow diagrams in your browser, from data records like Source [Amount] Target.

Here's a rough script that exports the outflows from several asset accounts:

LEDGER_FILE=examples/sample.journal
for f in checking saving cash; do 
  hledger areg $f -O tsv | tail +2 | sed -e "s/^/$f\t/"
done | cut -f1,6,7 | gsed -E -e 's/\$//' -e 's/([^\t]*)\t([^\t]*)\t([^\t]*)/\1 [\3] \2/' | grep '\[-' | gsed 's/\[-/[/'

hledger-sankeymatic is a better script to help you export hledger data to SankeyMATIC.

hledger-sankey

hledger-sankey screenshot

hledger-sankey-visualization

https://github.com/AlessandroW/hledger-sankey-visualization is a javascript that reads hledger's JSON output, and uses amCharts.

hledger-sankey-visualization screenshot

hledger-vega

hledger-vega (2022) is a set of scripts for producing custom charts from your hledger reports, using the powerful vega-lite.

hledger-vega screenshot

r-ledger

r-ledger is an R package for making reports and charts from hledger, Ledger or Beancount.

r-ledger screenshot

Grafana export script

Visualise your finances with hledger, InfluxDB, and Grafana (2017)

grafana screenshot

docker-finance metadata visualising

docker-finance, a hledger-based system, can visualise large quantities of metadata using ROOT.

docker-finance screenshot

Other charting tools

Fava

You can export to Beancount format and then use Fava, a web UI with many charts. See Beancount output or (improved) Beancount output in 2.x.

Ledger chart tools

Tools built for Ledger can sometimes be adapted to work with hledger also; or, hledger data can be exported to Ledger-readable files. Eg:

Spreadsheets

The most general, lowest-common-denominator way is to produce CSV output from a report, then drag the CSV file into a spreadsheet and use its charting tools. The balance command with --layout=bare and -N/--no-total is most often used. Eg:

hledger bal --layout bare -N expenses -o expenses.csv

ploterific

Here's another small example of plotting CSV data. ploterific (stack install hvega-theme ploterific) produces simple charts, in a HTML file that uses the Vega-Lite javascript library. Charts can also be saved as SVG or PNG.

hledger -f examples/bcexample.journal bal -O csv -N expenses -3 cur:USD \
    | sed 's/ USD//' \
    | ploterific -m Bar -f account:N -f balance:Q -c account -o a.html \
    && open a.html

ploterific example 1

Let's break down that command line:

  • -f examples/bcexample.journal - use this example file in the hledger repo. Omit this to use your default journal.
  • bal - run a balance report
  • -O csv - show it as CSV on stdout
  • -N - disable the final Total row
  • expenses - limit to accounts whose name contains expenses
  • -3 - summarise accounts to depth 3 and above
  • cur:USD - limit to balances in USD currency. If you use the $ symbol, it would be cur:\\$.
  • sed 's/ USD//g' - process the output with sed, stripping the USD symbols to leave bare numbers for ploterific. With $ it would be sed 's/\$//g'.
  • -m Bar - use Bar as the Vega-Lite mark type
  • -f account:N - use the account column as the first feature (X axis), treating values as names
  • -f balance:Q - use the balance column as a second feature (Y axis), treating values as quantities
  • -c account - use account values to select colours
  • -o a.html - save into a temporary HTML file
  • && open a.html - and view it in your web browser, on Mac; on other systems it might be xdg-open or start