
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
node-sparkline
Advanced tools
A lightweight and zero-dependencies pure Node.js sparkline generator
node-sparkline
A lightweight and zero-dependencies pure Node.js sparkline generator.
node-sparkline is a sparkline generator written in pure Node.js using ES6 and ES7 features with no dependency. It calculates points based on values to finally generate a polyline in a pure SVG (Scalable Vector Graphics) format. These values could be prices during the last 7 fays for an example.
The aim of this project is to provide a very simple, lightweight, zero-dependency, fast and fully-tested sparkline generator in SVG format and let user tune height, width, stroke color, stroke width and stroke opacity.
npm install node-sparkline
npm i -S node-sparkline
ESLint with Airbnb base rules. See Airbnb JavaScript Style Guide.
npm run lint
Mocha and Chai.
npm test
node-sparkline module exports one function named sparkline.
const sparkline = require('node-sparkline');
options
<Object>:
values
* <Array> An array of values to draw the sparkline.width
<Number> The width in pixels to fix for the generated SVG. Default: 135
height
<Number> The height in pixels to fix for the generated SVG. Default: 50
stroke
<String> The stroke color. An hexadecimal value or one of these generic names. Default: #57bd0f
strokeWidth
<Number> The stroke width in pixels. Min: 0
Default: 1.25
strokeOpacity
<Number> The stroke opacity. Min: 0
Max: 1
Default: 1
Returns: <String> The SVG tags of the generated SVG image
Throws: <InputError>
You can find examples here: docs/examples
In these examples please prefer a well-known and tested asynchronous logger over the use of console module.
const sparkline = require('node-sparkline');
const values = require('./values'); // values is an array
try {
const svg = sparkline({
values,
width: 135,
height: 50,
stroke: '#57bd0f',
strokeWidth: 1.25,
strokeOpacity: 1,
});
// svg is a string with SVG + polyline tags
// ...
} catch (e) {
console.error(e.toString());
}
DEBUG: used to debug node-sparkline.
Examples:
DEBUG=node-sparkline:*
will debug all node-sparkline modules that could use the debugger.DEBUG=-node-sparkline:*
will disable debugging any node-sparkline modules that could use the debugger.DEBUG=*
will debug all node-sparkline modules that could use the debugger plus other modules used in your project if they use an equivalent debugger.Errors emitted by node-sparkline inherit the native Error prototype.
{
name,
code,
message,
stack,
toString(),
}
name | code | description | module |
---|---|---|---|
InputError | |||
MISSING_VALUES | The values to draw the sparkline are missing. | src/index | |
INVALID_VALUES | values parameter must be an array. | src/index |
/
This project has a Code of Conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
Please take a moment to read our Contributing Guidelines if you haven't done so yet.
Please see our Support page if you have any questions or for any help needed.
For any security concerns or issues, please visit our Security Policy page.
MIT.
1.3.0 - delivery @06/06/2023
FAQs
A lightweight and zero-dependencies pure Node.js sparkline generator
The npm package node-sparkline receives a total of 3,651 weekly downloads. As such, node-sparkline popularity was classified as popular.
We found that node-sparkline demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.