GithubHelp home page GithubHelp logo

marianogappa / chart Goto Github PK

View Code? Open in Web Editor NEW
546.0 13.0 27.0 1.84 MB

Quick & smart charting for STDIN

Home Page: https://marianogappa.github.io/chart/

License: MIT License

Go 51.79% Makefile 0.12% HTML 48.09%
charting-library chart graphs chartjs

chart's Introduction

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.

chart's People

Contributors

jackyzhen avatar jawher avatar kuraio avatar marianogappa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chart's Issues

Support customised category name instead of `category 0`, `category 1` and etc

For example, I want to generate the bar chart for below csv

GaryZ@GaryZhus-MacBook-Pro-2 ~/Desktop $ cat test2.csv
,jack,jame
age,25,30
height,168,172

After running this command: cat test2.csv | chart bar , it generates below chart. Instead of showing jack and jame it shows category 0 and category 1 at the bottom.

example

Consider adding histogram support

This is a great tool to be sure, and I think it would be much better if it supported histograms. Often, when you are just trying to get a sense for some data, histogram is the most useful initial visualization.

I can't plot this :(

2016-08-29	0.0125
2016-09-06	0.0272
2016-09-07	0.0000
2016-09-08	0.0000
2016-09-15	0.0000
2016-09-16	0.0281
2016-09-19	0.0000
2016-09-22	3.6831
2016-09-28	8.1081
2016-10-06	8.1375
2016-10-14	14.0035
2016-10-20	0.5704
2016-10-25	15.0896
2016-10-26	1.1138
2016-10-28	8.4493
2016-11-01	3.6618
2016-11-03	0.1425
2016-11-16	100.0000
2016-11-17	2.2675
2016-11-22	5.2985
2016-11-23	0.0000
2016-11-24	0.0061

All line charts are zero based?

If I render a line chart with or without the -zero-based argument, the y-axis is always anchored at zero. Is the default y-axis supposed to be based on the minimum value?

Line graphing requests with grouping

Overview

I'm attempting to use chart to graph large number of outbound requests. My data structure my log tool outputs looks like so:

{"timestamp":"2017-08-07T23:59:21.434927285Z"}
{"timestamp":"2017-08-07T23:59:21.4703704Z"}
{"timestamp":"2017-08-07T23:59:21.797074466Z"}
{"timestamp":"2017-08-07T23:59:21.891435198Z"}
{"timestamp":"2017-08-07T23:59:21.993443695Z"}

Using chart, I was expecting like the following to produce a line graph that groups the entries and increases the Y axis. I'm obviously doing something wrong as instead I get a flat line.

screen shot 2017-08-09 at 1 17 09 pm

The command I had come up with to handle the format my logs output is the following:

cat test.json | jq -r .timestamp | awk '{print $0 "\t" "1"}' | chart line log --date-format 2006-01-02T15:04:05.999999999Z

Is grouping on the y axis something that chart supports? Or is it something that should be done before hand? If anyone would like to play with something like this themselves, I've uploaded a ~200000 lines of logs in the above format. http://www38.zippyshare.com/v/xAMPdzeg/file.html

Non-zero-based bar charts shouldn't be the default

Because we judge the values in a bar chart by the lengths of the bars, not by the positions of the ends of the bars, the axis scale must include zero. By chopping off the bottoms of the bars, we increase the resolution of the chart, but we distort the apparent values encoded by the bars.

Size issue with pie charts since Chart.js upgrade

Pie charts exceed viewport after updating Chart.js to 2.6.

We've looked into it briefly with no success. Since pie charts have very disimilar aspect ratio constraints compared to all other charts, unless anyone has a better idea I will simply conditionally just use half the viewport when it's a pie chart to solve this.

Implement basic performance improvements

Running a frequency pie chart off a 250k line file takes about 10 seconds on a fast laptop. This is a ballpark figure, but the use case is not that far-fetched. I'd expect it to be quite common to base charts off a million lines or so; at least for my use cases.

While not interested in adding complexity to chart's source code, there are some quick wins that can improve the response time quite a bit:

  • At the moment, input is read from STDIN into an empty slice. Without a size hint, this is incurring in unnecessary allocations.
  • Preprocessing the format requires a pass through the whole slice. The initial pass could do this step at the same time; this would save a whole pass.
  • Does every single line need to be processed to infer the format?

Releases link broken

I found your tool while trying to figure out gnuplot.

The README's releases link goes to a GitHub 404 error page.

https://github.com/marianogappa/chart/v4/releases

The releases that do exist are about 5 years old.

Where can I get the latest release?

add option to render chart in terminal

as my main use case would be in a terminal, i'd prefer not to open a browser but get the gist of it right where i'm working with the data. horizontal bar chart would be best i guess?

Can't chart date-driven time series on line or scatter charts

With e.g.

a	2017-03-12 20:21:53
a	2017-03-12 20:21:56
a	2017-03-12 20:21:57
a	2017-03-12 20:21:58
a	2017-03-12 20:22:01
a	2017-03-12 20:35:15
a	2017-03-12 20:40:04
a	2017-03-12 20:40:05
a	2017-03-12 20:45:15
cat /tmp/a | chart line --date-format "2006-01-02 03:04:05"
FATA[0000] Could not construct chart because [Couldn't find values to plot.]

Debug reveals the format was recognised but the lines weren't used, but it doesn't clarify why

$ cat /tmp/a | chart line --date-format "2006-01-02 03:04:05" -debug
Lines read	1065
Line format inferred	sd
Lines used	0
Float column count	0
String column count	0
Date/Time column count	0
Date format	2006-01-02 03:04:05
Chart type	line
Scale type	linear
Separator	[tab]

Charting doesn't work even if a float is used instead if a string

141763146	2017-03-12 20:40:05
141763147	2017-03-12 20:40:05
141763148	2017-03-12 20:40:05
141763149	2017-03-12 20:40:05
141763150	2017-03-12 20:40:05
141763151	2017-03-12 20:40:05
141763152	2017-03-12 20:40:05
141763153	2017-03-12 20:40:05
141763156	2017-03-12 20:45:15
Lines read	1065
Line format inferred	fd
Lines used	0
Float column count	0
String column count	0
Date/Time column count	0
Date format	2006-01-02 03:04:05
Chart type	pie
Scale type	linear
Separator	[tab]

Enable using the chartjs subpackage separately

A wealth of use cases would be enabled if charts could be made programatically instead of using the CLI tool proper, e.g. #16

Required changes are minimal:

  • Calculating minFSS and maxFSS within the subpackage rather than receiving them
  • Producing the full HTML/JS/CSS should be parameterised and implemented within the subpackage
  • Examples, better godoc and a README in the subpackage

Chart.js' scatter line charts care about data point ordering

The following dataset

2 4
1 3
4 4
3 3

Yields the following scatter line chart
screen shot 2017-07-05 at 8 24 08 pm

While this behaviour is very flexible, I believe anyone wanting to plot a scatter line chart would expect the x values to be sorted, and this should be the default behaviour.

The aforementioned issue also happens when the x axis is composed of time-based data points.

Chart "Lines used" cannot exceed 10

this is best outlined with this output from this bash script (which is taken from the readme)

~ history | awk '{print $2}' | chart -debug
Lines read	10021                                                 
Line format inferred	sf
Lines used	10
Float column count	1
String column count	1
Date/Time column count	0
Chart type	pie
Scale type	linear
Separator	[tab]

there are far more commands used in my history than 10, but it seems like the display never exceeds 10. It just ends up lumping thousands of commands into a column "Other". This is true for various other graphs I attempt as well (at least simple string frequency graphs that I know how to use)

This appears to be by design, is there a way to tell chart to just graph "everything"?

Go install dependency issue

When running go install github.com/marianogappa/chart@latest I am getting

go: github.com/marianogappa/chart imports
        github.com/Sirupsen/logrus: github.com/Sirupsen/[email protected]: parsing go.mod:
        module declares its path as: github.com/sirupsen/logrus
                but was required as: github.com/Sirupsen/logrus

Provide a default implementation for the case of only one float series

There's a very common case for input that looks like this:

1
5
10
11
12
...

It's not clear what chart should do in this case. The two most likely charts that one wants in this case (in my opinion) are:

  1. histogram (most likely)
  2. line chart with the data series being the y-axis, and with an implicit monotonically increasing x-axis (i.e. want to see the evolution of the data series line by line, e.g. the evolution of a stock price every hour)

At the moment, however, chart just returns: FATA[0000] couldn't find values to plot.

Given that we don't support histograms, 2) should be supported instead.

Line parsing strategy is incorrect in some cases

Let's say the data is separated by commas. This input:

1,2,3
1,,3
1,2,3

Should be interpreted as 3 rows and 3 columns with all floats, the second row having a zero for its second column.

This is not what happens at the moment. Instead, the second row is ignored as it's interpreted as having only 2 columns. This doesn't make sense except in the case where the separator is a space, where many subsequent spaces are trimmed to one as a preprocessing step.

This preprocessing should only be applied when the separator is a space.

Support (optional) legends in line charts

At the moment, line charts don't show legends, which can make the chart hard to read when there are multiple series. It'd be great if there is an optional command line option for a comma separated headers for each field, and when it's specified, the headers are used for rendering legends for lines.

float deviation make chart look ugly

input csv data:

0,0.604660,0.940509
1,0.664560,0.437714
2,0.424637,0.686823
3,0.065637,0.156519
4,0.096970,0.300912
5,0.515213,0.813640
6,0.214264,0.380657
7,0.318058,0.468890
8,0.283034,0.293102
9,0.679085,0.218553

cmd: cat data.csv | chart line ,

got:
screenshot from 2017-07-01 16 11 08

Support writing the HTML to a file

Maybe introduce an command line option -o or something like that, which is followed by a file path for writing the chart to. It can be super useful for generating a lot of charts using scripts.

Evaluate removing bezier curves in line charts

Bezier curves are not only slower to render but more importantly confusing in some cases, concretely when they violate the function definition, by appearing to have more than one value of y for a single value of x.

`-help` does not output help text before `stdin` closes.

$ chart -help
# waits for stdin
^C

but,

$ echo | chart -help
  -date-format string
    	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	Show help.
  -help
    	Show help.
...

I expect -help to show help immediately without waiting for stdin.

Categorical line charts are broken

The code adds linear scale to categorical line charts on the x axis. This confuses Chart.js into thinking it's a scatter line chart. Moreover there are no cheat stheet examples for categorical line charts!

This needs to be resolved ASAP.

Support multiple series designated by a string field in line charts

For example, with the following data

foo	2017-06-23	1
foo	2017-06-24	2
foo	2017-06-25	3
foo	2017-06-26	4
foo	2017-06-27	5
foo	2017-06-28	6
bar	2017-06-23	9
bar	2017-06-24	8
bar	2017-06-25	7
bar	2017-06-26	6
bar	2017-06-27	5
bar	2017-06-28	4

chart line --date-format 2006-01-02 can generate a line chart with 2 series, foo and bar.

Support more colors

When there are a lot of lines/bars etc in a chart, the same color gets reused, which can make it hard to read.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.