![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.
react-line-graph
Advanced tools
A lightweight and simple line graph component.
Supports Bezier smoothing, easy customization, and hover interactivity.
An nvmrc
file is included if using nvm.
OS X & Linux:
npm install react-line-graph
Usage is quite simple. First, import the component (React 16.8.0 or higher is required as an installed dependency or CDN):
import { LineGraph } from 'react-line-graph'
Render the line:
const data = [10,0,-2.5,540]; // LineGraph reads these as y-values, automatically spaces them out evenly
<LineGraph data={data}/>
or
const data = [[0,20], [-30,40], [-88.9, 9]]; // LineGraph reads these as x,y pairs
<LineGraph data={data}/>
or
const data = [ { x: 10, y: 2 }, {...}];
<LineGraph data={data}/>
Customizing your graph is easy:
const data = [10,0,-2.5,540];
const props = {
data,
smoothing: 0.3,
accent: 'palevioletred'
fillBelow: 'rgba(200,67,23,0.1)',
hover: true,
};
<LineGraph {...props}/>
This renders a smooth graph with hovering enabled. The y-value is passed down to child components upon hover by default, but this can be changed.
Key | Type | Default | Description |
---|---|---|---|
data | Array (required) | [] | The data points to render. May be of form [a,...,b], [[a,b],...,[c,d]], or [{x: a, y: b},...,{...}] where a,b,c,d are some numbers |
smooth | Number (0 to 1) | 0 | The Bezier smoothing ratio to apply. |
accent | String | 'black' | The color of the line accents |
fillBelow | String | 'none' | The color of the fill below the line. |
fillAbove | String | 'none' | The color of the fill above the line. |
hover | Boolean | false | Enables hovering. Hovering will render a line and will pass on the hovered value to children (this component is child-aware). |
gridX | Boolean | false | Shows the grid-lines along the x-axis (vertical lines). |
gridY | Boolean | false | Shows the grid-lines along the y-axis (horizontal lines). |
debug | Boolean | false | Displays debug information on graph, including anchor and control points. |
width | String | '100%' | The width of the component within a container element. |
height | String | '100%' | The height of the component within a container element. |
compression | Number | 0.1 | The compression factor of the data-set from 0 to 1. Compresses data linearly from top and bottom along the Y-axis. |
onHover | Function | () => {} | The callback function to which an array containing currently hovered point ([x, y]) is passed when the user hovers. Useful for displaying the hovered value in the parent component (the one you write). Only active when 'hover' is set to true. |
For more examples and usage, please refer to the Wiki (under development).
For developers (OS X / Linux):
From within the root directory:
npm install
npm start
From within the root directory:
npm test
Umair Nadeem – @UmairNadeem – umair@umairnadeem.com
Distributed under the MIT license. See LICENSE
for more information.
https://github.com/umairnadeem/react-line-graph
git checkout -b feature/fooBar
)git commit -am 'Add some fooBar'
)git push origin feature/fooBar
)FAQs
A simple and lightweight line graph
The npm package react-line-graph receives a total of 32 weekly downloads. As such, react-line-graph popularity was classified as not popular.
We found that react-line-graph 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.