Skip to content

portnov/chart-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chart-cli README

Build Status

This repo provides a chart command-line utility. chart is aimed to generate basic 2D charts from command line easily.

The chart utility is not aimed to give full control over generated charts, or to generate all possible types of charts - you may anytime do that by use of gnuplot or Chart package. This utility, instead, gives you a very quick way of generating some most useful types of charts.

Usage example:

$ cat > input.txt
X	Y1	Y2
1	1	3
2	4	6
3	7	4
4	5	8
6	3	2
^D

$ chart --header -o lines.png input.txt

Result:

lines.png

Supported chart types for now are:

  • Line charts (the default one)
  • Bar charts (clustered and stacked)
  • Area charts
  • Point charts

Other chart types may be added later.

Supported output formats are:

  • PNG (the default one)
  • SVG
  • PS (PostScript)
  • PDF

Output file format is automatically detected by specified output file name. If output file name is not specified explicitly, chart.png will be used.

Performance

Plotting the file bigfile.txt (2.8Mb, 230 000 + lines) with

chart -o bigfile.png --line-ending=unix -d' ' -i --width=1920 --height=1200 points bigfile.txt 

takes about 45 seconds on my machine (i5 2.8 GHz).

Expected input format

Input data are expected to be provided as a series of lines; each line may represent either one point to plot, or several points at the same X coordinate.

The first line may optionally represent names of the columns.

Other lines should consist of several numbers. Numbers are separated with a delimiter. Default delimiter is TAB characater; you may specify another with -d command line option.

If only one number per line is provided, then these numbers will be used as Y values; for X values, line numbers (starting with 1) will be used.

If more than one number per line is provided, then for most chart types (except for bar charts) the first column will be used as X values, and other will be used as Y values.

In the first column, date/time values may be provided instead of numbers (to be used as values along X axis). Supported date/time formats are:

  • DD.MM.YYYY
  • YYYY/MM/DD
  • `12 September 2012'
  • today, tomorrow, yesterday
  • `in 2 days', '3 weeks ago'
  • `last monday', 'next friday'
  • last month' (1th of this month), next year' (1th of January of next year)

(thanks to dates package).

Command-line interface

I'll put it here for quick reference; more actual information is always accessible with chart --help:

Usage: chart [-o|--output OUTPUT.png] [COMMAND] [-1|--header]
             [--line-ending UNIX|DOS|MACOS] [-d|--delimiter CHAR] [-i|--index]
             [-t|--title TITLE] [-w|--width WIDTH] [-h|--height HEIGHT]
             [-b|--background COLOR] [-f|--foreground COLOR]
             [-L|--legend ON|OFF] [INPUT.txt]
  Make a chart

Available options:
  -o,--output OUTPUT.png   write output to OUTPUT.png. Default is chart.png.
  -1,--header              first line contains column headers
  --line-ending UNIX|DOS|MACOS
                           specify line endings variant to be used (default: LF)
  -d,--delimiter CHAR      specify fields delimiter ('\t' by default)
  -i,--index               if enabled, treat input data as if there was an
                           additional first column, containing line numbers,
                           starting from 1
  -t,--title TITLE         set chart title to TITLE
  -w,--width WIDTH         specify chart width, in pixels (default: 800)
  -h,--height HEIGHT       specify chart height, in pixels (default: 600)
  -b,--background COLOR    specify background color name (see SVG 1.1 spec)
  -f,--foreground COLOR    specify foreround color name (see SVG 1.1 spec)
  -L,--legend ON|OFF       enable or disable the legend (default: True)
  INPUT.txt                Input data file. If not provided, standard input will
                           be used.
  -h,--help                Show this help text

Available commands:
  line                     Make a line chart
  area                     Make an area chart
  points                   Make a points chart
  bar                      Make a bar chart

Installation

Prerequisites for Debian / Ubuntu Linux:

$ sudo apt install libgmp-dev libgtk-3-dev libgirepository-1.0-1 libgirepository1.0-dev gobject-introspection

Prerequisites for Mac OS X:

$ brew install gobject-introspection gtk+ gtk+3

Install it by stack:

$ sudo apt-get install stack
$ git clone https://github.com/portnov/chart-cli.git
$ cd chart-cli/
$ stack install

Releases

No releases published

Packages

No packages published