Quick & smart charting for STDIN
Clone or download
Permalink
Failed to load latest commit information.
chartjs Colors snippet on R. Aug 19, 2018
dataset Removes logrus dependency. Sep 1, 2018
format Simplifies ChartJS constructor Aug 12, 2018
img Adds animated GIF for README Aug 25, 2018
testdata Default colors updated, legacy colors available, new gradient colors … Dec 2, 2017
vendor Removes dependencies. Updates mods. Sep 1, 2018
.gitignore Removes .DS_Store Aug 4, 2018
.goreleaser.yml Isolates Chart.js specific code into a chartjs package Aug 4, 2018
.travis.yml Calculates minFSS/maxFSS inside chart.js package. Adds comments. #39 Aug 12, 2018
LICENSE Initial commit Aug 20, 2016
Makefile Fixes broken tests. #39 Aug 11, 2018
README.md Adds animated GIF to README Aug 25, 2018
chart_type.go Isolates dataset in order to package it. #39 Aug 11, 2018
chart_type_test.go Isolates dataset in order to package it. #39 Aug 11, 2018
cheatsheet_test.go Implements OutputMode and moves template content to chartjs package #39 Aug 19, 2018
debug.go Makes dataset a subpackage. Aug 11, 2018
debug_test.go Makes dataset a subpackage. Aug 11, 2018
freq.go Isolates dataset in order to package it. #39 Aug 11, 2018
freq_test.go Isolates dataset in order to package it. #39 Aug 11, 2018
go.mod Removes dependencies. Updates mods. Sep 1, 2018
go.sum Removes dependencies. Updates mods. Sep 1, 2018
index.html Implements OutputMode and moves template content to chartjs package #39 Aug 19, 2018
main.go Removes logrus dependency. Sep 1, 2018
options.go Simplifies ChartJS constructor Aug 12, 2018
options_test.go Tests additional options. Aug 5, 2018
tmpfile.go Removes logrus dependency. Sep 1, 2018

README.md

chart Build Status Coverage Status GitHub license Go Report Card

Quick & smart charting for STDIN

Blogpost

Chart example use

Learn by example!

Cheatsheet

Syntax

chart [options]
  • pie: render a pie chart
  • bar: render a bar chart
  • line: render a line chart
  • scatter: render a scatter plot chart
  • log: use logarithmic scale (bar chart only)
  • legacy-color: use legacy colors
  • gradient: use color gradients
  • ' '|';'|','|'\t': this character separates columns on each line (\t = default)
  • -t|--title: title for the chart
  • -x: label for the x axis
  • -y: label for the y axis
  • --date-format: Sets the date format, according to https://golang.org/src/time/format.go
  • --debug: Use to make sure to double-check the chart is showing what you expect.
  • -h|--help: Show help
  • --zero-based: Makes y-axis begin at zero

Installation

go get -u github.com/marianogappa/chart

or get the latest binary for your OS in the Releases section.

Example use cases

  • Pie chart of your most used terminal commands
history | awk '{print $2}' | chart

Pie chart of your most used terminal commands

  • Bar chart of today's currency value against USD, in logarithmic scale
curl -s http://api.fixer.io/latest?base=USD | jq -r ".rates | to_entries| \
    map(\"\(.key)\t\(.value|tostring)\")|.[]" | chart bar log -t "Currency value against USD"

Bar chart of today's currency value against USD, in logarithmic scale

  • Bar chart of a Github user's lines of code per language (requires setting up an Access Token)
USER=???
ACCESS_TOKEN=???
curl -u $USER:$ACCESS_TOKEN -s "https://api.github.com/user/repos" | \
    jq -r 'map(.languages_url) | .[]' | xargs curl -s -u $USER:$ACCESS_TOKEN | \
    jq -r '. as $in| keys[] | [.+ " "]+[$in[.] | tostring] | add' | \
    awk '{arr[$1]+=$2} END {for (i in arr) {print i,arr[i]}}' | \
    awk '{print $2 "\t" $1}' | sort -nr | chart bar

Bar chart of a Github user's lines of code per language (requires setting up an Access Token)

  • Line chart of the stargazers of this repo over time up to Jan 2017 (received some attention after the publication of this blogpost)
curl -s "https://api.github.com/repos/marianogappa/chart/stargazers?page=1&per_page=100" \
-H"Accept: application/vnd.github.v3.star+json" | \
jq --raw-output 'map(.starred_at) | .[]' | awk '{print NR "\t" $0}' | \
chart line --date-format 2006-01-02T15:04:05Z

Line chart of Github stargazers of this repo over time

Charting MySQL output

chart works great with sql, or with any mysql -Nsre '...' query.

I don't trust the chart is correct

Me neither. Add --debug to double-check (e.g. some rows could be being ignored due to parse failures, separator could be incorrect, column types could be inferred wrongly).

$ cat /tmp/c | ./chart bar --debug
Lines read  3
Line format inferred    ff
Lines used  3
Float column count  2
String column count 0
Date/Time column count  0
Chart type  bar
Scale type  linear
Separator   [tab]

Details

  • chart infers STDIN format by analysing line format on each line (doesn't infer separator though; defaults to \t) and computing the winner format.
  • it uses the awesome ChartJS library to plot the charts.
  • when input data is string-only, chart infers a "word frequency pie chart" use case.
  • should work on Linux/Mac/Windows thanks to open-golang.

Known issues

Contribute

PRs are greatly appreciated and are currently being merged. If you have a use case that is not supported by chart, I'd love to hear about it, but if it's too complex I'd recommend you to try gnuplot.