plo

plotter

A node.js module that turns an array of data into a graph in a pdf document. Uses gnuplot and ps2pdf.

Showing:

Popularity

Downloads/wk

8

GitHub Stars

31

Maintenance

Last Commit

1yr ago

Contributors

4

Package

Dependencies

1

Size (min+gzip)

5.5KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

nodejs-plotter is a node.js module that turns an array of data into a graph. Uses gnuplot and ps2pdf.

Installation

Prerequisites:

sudo apt-get install gnuplot ghostscript

If you have npm installed, just run:

npm install plotter

Usage

var plot = require('plotter').plot;

plot({
    data:       [ 3, 1, 2, 3, 4 ],
    filename:   'output.png'
});

Plotting is achieved by calling the plot function with an object containing various properties. Both 'data' and 'filename' are essential, all other properties are optional.

Output format

This defaults to .png but specifing format: svg changes the output to .svg and format: pdf changes the output format to .pdf.

var plot = require('plotter').plot;

plot({
    data:       [ 3, 1, 2, 3, 4 ],
    filename:   'output.svg',
    format:     'svg'
});

Formatting

The following properties can be used:

  • title : Sets the title of the graph
  • xlabel : Sets the label on the x axis of the graph
  • ylabel : Sets the label on the y axis of the graph
  • logscale : Makes the y axis of the graph appear in a log scale
  • style : The style of the lines on the graph. Possibilites include lines (default), points and linespoints
  • nokey : Disables the graph key
  • x_begin : Specifies the starting point along X axis on the graph

The following example shows these in use:

plot({
    data:       [ 3, 1, 2, 3, 4 ],
    filename:   'output.pdf',
    style:      'linespoints',
    title:      'Example \'Title\', \\n runs onto multiple lines',
    logscale:   true,
    xlabel:     'time',
    ylabel:     'length of string',
    format:     'pdf',
    x_begin:    0
});

Specifing X and Y values

plot({
    data:       { 'line' : { 1: 5, 5: 6 } },
    filename:   'output.png'
});

Instead of specifing an array for data, you can specify an object with a named series inside.

Multiple Series

plot({
    data:       { 'tick' : [ 3, 1, 2, 3, 4 ], 'line' : { 1: 5, 5: 6 } },
    filename:   'output.png'
});

You can specify multiple series inside an object.

Moving Averages and Maximums

plot({
    data:       { 'tick' : [ 3, 1, 2, 3, 4, 15, 3, 2, 4, 11 ],
        'tick2' : [ 3, 10, 2, 30, 4, 15, 3, 20, 4, 11 ] },
    filename:   'output.png',
    moving_avg: 4
});

This will plot the points with a 4-point moving average. A moving_max can also be specified, which if applied alongside a moving_avg will be calculated after the moving average.

Time Formatting

plot({
    data:       { 'temperature' :
            { 1357162672: 22, 1357162782: 23, 1357162892: 24 } },
    time:       'hours',
    filename:   'output.png'
});

The x axis can be formatted as a time series if the x values are given as a unix time. The time property can be specified as either 'hours' (the default), 'days' or with a gnuplot time format like '%H:%M'.

Other options

The options object might additionally contain the following:

OptionDescriptionExample
execArguments for the gnuplot processoptions.exec = { cwd : '/home/user/images' };
finishCallback executed when the gnuplot process finishesoptions.finish = function(){ Console.log('Success!'); };

LICENSE

MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100