Charts and Graphs
Tips and techniques for producing graphical charts.
Generally we run a hledger report and
- select CSV(/SSV/TSV) output (-o foo.csv)
- disable the Total row (-N/--no-total))
- and show numbers apart from their commodity symbols (--commodity-column; or in hledger master, --layout=bare)
Eg:
hledger bal assets liabilities --no-total --commodity-column -o report.csv
Then there are many ways to convert CSV to charts.
Spreadsheet
Drag the CSV file into your favourite spreadsheet app and use its charting tools.
ploterific
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. An example:
hledger -f examples/bcexample.hledger 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
Let's break down that command line:
-f examples/bcexample.hledger
- 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 rowexpenses
- limit to accounts whose name containsexpenses
-3
- summarise accounts to depth 3 and abovecur:USD
- limit to balances inUSD
currency. If you use the$
symbol, it would becur:\\$
.sed 's/ USD//g'
- process the output with sed, stripping theUSD
symbols to leave bare numbers for ploterific. With$
it would besed 's/\$//g'
.-m Bar
- useBar
as the Vega-Lite mark type-f account:N
- use theaccount
column as the first feature (X axis), treating values as names-f balance:Q
- use thebalance
column as a second feature (Y axis), treating values as quantities-c account
- useaccount
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 bexdg-open
orstart
Here is the same chart but with the colour set by the balance:
hledger -f examples/bcexample.hledger bal -O csv -N expenses -3 cur:USD \
| sed 's/ USD//' \
| ploterific -m Bar -f account:N -f balance:Q -c balance:Q -o a.html
gnuplot, R, other
Check out the tools at https://plaintextaccounting.org/#reports (hreports, ledger-plot, ledger-plots, ludget, r-ledger..)
hledger-vega
New in 2022: https://github.com/xitian9/hledger-vega is a set of scripts for producing custom charts from your hledger reports, using the powerful vega-lite. It works best with hledger 1.24.99+. https://nest.pijul.com/simonmichael/hledger-vega is another variant.