项目作者: marianogappa

项目描述 :
Quick & smart charting for STDIN
高级语言: Go
项目地址: git://github.com/marianogappa/chart.git
创建时间: 2016-08-20T08:04:36Z
项目社区:https://github.com/marianogappa/chart

开源协议:MIT License

下载


chart Build Status Coverage Status GitHub license Go Report Card

Quick & smart charting for STDIN

Blogpost

Chart example use

Learn by example!

Cheatsheet

Syntax

  1. 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

  1. go install github.com/marianogappa/chart@latest

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

Example use cases

  • Pie chart of your most used terminal commands
    1. 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
    1. curl -s http://api.fixer.io/latest?base=USD | jq -r ".rates | to_entries| \
    2. 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)
    1. USER=???
    2. ACCESS_TOKEN=???
    3. curl -u $USER:$ACCESS_TOKEN -s "https://api.github.com/user/repos" | \
    4. jq -r 'map(.languages_url) | .[]' | xargs curl -s -u $USER:$ACCESS_TOKEN | \
    5. jq -r '. as $in| keys[] | [.+ " "]+[$in[.] | tostring] | add' | \
    6. awk '{arr[$1]+=$2} END {for (i in arr) {print i,arr[i]}}' | \
    7. 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)
    1. curl -s "https://api.github.com/repos/marianogappa/chart/stargazers?page=1&per_page=100" \
    2. -H"Accept: application/vnd.github.v3.star+json" | \
    3. jq --raw-output 'map(.starred_at) | .[]' | awk '{print NR "\t" $0}' | \
    4. 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).

  1. $ cat /tmp/c | ./chart bar --debug
  2. Lines read 3
  3. Line format inferred ff
  4. Lines used 3
  5. Float column count 2
  6. String column count 0
  7. Date/Time column count 0
  8. Chart type bar
  9. Scale type linear
  10. 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.

Development

  • Requires Go version >= 1.11 with module support for building and testing.

  • Requires Goreleaser for building and publishing releases.

  • See Makefile for build and test commands.