• Stars
    star
    544
  • Rank 81,699 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Quick & smart charting for STDIN

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

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.

More Repositories

1

sqlparser

Simple SQL parser meant for querying CSV files
Go
392
star
2

flowbro

Real-time flowchart visualisation for Kafka-based distributed systems.
Go
121
star
3

sql

MySQL & PostgreSQL pipe
Go
86
star
4

gomario

Basic Golang text-mode Mario-like game
Go
76
star
5

cheesse

Package, server, cli tool and WebAssembly binary for chess use cases.
Go
63
star
6

ostinato

A chess library that runs on the server (Scala) and on the browser (ScalaJS).
Scala
51
star
7

jira-cli

Lightweight bash script for easily querying your company's JIRA issues
Shell
42
star
8

crypto-candles

Universal crypto candlestick iterator library & CLI
Go
13
star
9

sd

Diffs two streams of newline-separated strings, timing them out if necessary.
Go
13
star
10

leetcode

Go
12
star
11

parseq

Parallel processing with sequential output, respecting order of input
Go
10
star
12

Spreadsheet-to-MediaWiki-table-Converter

Converts an Google Spreadsheet/Excel Sheet to MediaWiki table format, providing styling features.
PHP
10
star
13

mediawiki-table-utility

A handy tool to convert tab-separated tables (e.g. Excel, Google Spreadsheets) to the MediaWiki table format (e.g. Wikipedia)
HTML
7
star
14

kafka-examples

A suite of working test cases for getting started with Apache Kafka painlessly (in Scala)
Scala
5
star
15

bookie

Indexing for Kafka queues.
Go
4
star
16

ponganoid

A simple cli game reminiscent of Pong and Arkanoid.
Go
4
star
17

sctool

Starcraft: Remastered replay analyzer library and CLI tool
Go
3
star
18

hackerrank

Go
3
star
19

happiest-state-python

Determining the happiest USA state using Twitter streams and Sentiment Analysis in Python.
Python
3
star
20

blacklist

DNS-based blacklist checker
Go
3
star
21

fsm

Ridiculously hacky tool to help me keep in touch with my friends.
Go
2
star
22

iknowkungfoo

Website aiming to provide easiest way to learn Algos & DS for FAANGs
Go
2
star
23

bincli

Binance CLI
Go
2
star
24

cheesse-examples

JavaScript
2
star
25

crypto-predictions

State machine-based engine for tracking crypto-related predictions across social media posts.
Go
2
star
26

ostinato-examples

A quick and dirty demo to showcase the ostinato library
JavaScript
2
star
27

termserve

Go
1
star
28

chessboard-image-builder

Shell
1
star
29

kafkasimpletest

A working smoke int test for Apache Kafka to start up a Scala project
Scala
1
star
30

signal-checker

cli tool, server & library to check the results of crypto signals against an exchange's historical data.
Go
1
star
31

tablerenderer

A minimalist script to render an associative array as a MySQL result table
PHP
1
star
32

marianogappa.github.io

My blog about Software Engineering and Music Production
HTML
1
star