![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Time Series Charting Canvas API
var Chart = require('chart');
var chart = new Chart;
var ee = require('events').EventEmitter;
var datasource = new ee;
chart.series(datasource);
chart.to(document.getElementById('mychart'));
setInterval(function() {
var random = Math.floor(Math.random()*100);
datasource.emit('data',{y:random});
},1000);
var d1 = new ee;
var d2 = new ee;
chart.series(d1);
chart.series(d2);
// or
chart.series([d1,d2])
// or
chart.series(d1,d2);
To have the data you emit treated as separate y-axises with different scaling, simply pass a second object {multiple:true} in your emit
datasource.emit('data',{stockPrice:235,temperature:88},{multiple:true});
Event types that chart.series responds to are
'data' - provides data for timeseries and optional labels
'stop' - stops the timeseries for that datastream
<div id='legend'></div>
chart.legend(document.getElementById('legend'));
Legend is automatically created with the data that is sent. To visualize and interact with a legend, use the .legend callback
<link type='text/css' rel='stylesheet' href='legend.css' />
Also in the root directory of this package is a file called legend.css that you should include.
datasorce.emit('data',{'units sold':9.2})
datasorce1.emit('data',{'units sold':9.2})
datasorce2.emit('data',{'current energy consumption':30})
You can set the following colors. Defaults to below.
chart.color.bg = '#FFF'; // the background color
chart.color.grid = '#c9d6de'; // a pleasant grid
chart.color.xlabel = '#000'; // the color of the x-axis labels
chart.color.xline = '#000'; // the color the x-axis line
chart.color.ylabel = '#000'
chart.color.yline = '#000';
chart.color.interactionline = '#000';
You can also create a preferred ordered set of colors for the lines. You must supply the lines in six digit RGB hexadecimal like so:
chart.color.line = ['#FF0000','#00FF'];
Any colors you do not supply will be provided for.
chart.color.line = ['#FF0000',undefined,'#00FF'];
// will choose '#FFFF00' for the second element automatically.
You can also set colors for the legend, through these CSS classes
div.legend {
}
div.legend div.axisname {
}
You can set the render modes any time, change them at any time like so:
chart.rendermode = "line"; // defaults to line, also can use "linefill", "bar"
You can also set the rendermode from a specific event and it will take precedence. You can switch this at will.
datasource.rendermode = "linefill";
chart.inspect() returns the current data passing through.
// to install tap, simply npm install tap
tap ./test
Author: David Wee rook2pawn@gmail.com License: MIT/X11
FAQs
event based time series charting API
The npm package chart receives a total of 21 weekly downloads. As such, chart popularity was classified as not popular.
We found that chart 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.