2.0.2 • Published 5 years ago

react-svg-line-chart v2.0.2

Weekly downloads
503
License
MIT
Repository
github
Last release
5 years ago

react-svg-line-chart

npm package Travis Codecov Module formats

A lightweight responsive line chart component for React using only SVG

Getting started

react-svg-line-chart

You can download react-svg-line-chart from the NPM registry via the npm or yarn commands

yarn add react-svg-line-chart
npm install react-svg-line-chart --save

If you don't use package manager and you want to include react-svg-line-chart directly in your html, you could get it from the UNPKG CDN

https://unpkg.com/react-svg-line-chart/umd/react-svg-line-chart.js

Demo

See Demo page

Usage

import React from 'react'
import LineChart from 'react-svg-line-chart'

const data = []

for (let x = 1; x <= 30; x++) {
    data.push({ x: x, y: Math.floor(Math.random() * (100)) })
}

export default class MyComponent extends React.Component {
    state = {
        activePoint: null,
    }

    handlePointHover = (activePoint, e) => {
        this.setState({activePoint})
    }

    render() {
        const {activePoint} = this.state
        return (
            <LineChart
            data={data.map((point, i) => ({...point, active: point.x === activePoint.x ? true : false}))}
            pointsOnHover={this.handlePointHover}
            />
        )
    }
}

Props

NamePropTypeDescriptionDefault
areaColorStringArea color (hex, rgb...)"#34495e"
areaOpacityNumberArea opacity.5
areaVisibleBooleanArea visibilityfalse
axisColorNumberAxis color"#34495e"
axisOpacityNumberAxis opacity.5
axisVisibleBooleanAxis visibilitytrue
axisWidthNumberAxis width1
dataArray of data Objectsdata is {x: number, y: number, active: bool})[]
gridColorStringGrid color"#34495e"
gridOpacityNumberGrid color.5
gridVisibleBooleanGrid visibilitytrue
gridWidthNumberGrid width1
labelsCharacterWidthNumberLabels character with (depending on your font) to calculate the width of Y labels10
labelsColorStringLabels color"#34495e"
labelsCountYNumberY labels count5
labelsFormatXFunctionCustom X labelsx => x
labelsFormatYFunctionCustom Y labelsy => y
labelsHeightXNumberX labels height (depending on your font)12
labelsOffsetXNumberX labels offset15
labelsOffsetYNumberY labels offset15
labelsStepXNumberX labels step1
labelsVisibleNumberLabels visibilitytrue
pathColorStringPath color"#34495e"
pathOpacityNumberPath opacity1
pathSmoothingNumberBetween 0 and 1 or null to disablenull
pathVisibleBooleanPath visibilityfalse
pathWidthNumberPath width1
pointsColorStringPoints color"#fff"
pointsIsHoverOnZoneBooleanpointsOnHover function callback called on zone hover instead of points hoverfalse
pointsOnHoverFunctionCallback when one point is hovered(point, event) => {}
pointsRadiusNumberPoints radius4
pointsStrokeColorStringPoints stroke color"#34495e"
pointsStrokeWidthNumberPoints stroke width2
pointsVisibleBooleanPoints visibilitytrue
viewBoxHeightNumberSVG viewport height300
viewBoxWidthNumberSVG viewport width800

Contributing

  • ⇄ Pull/Merge requests and ★ Stars are always welcome.
  • For bugs and feature requests, please create an issue.
  • Pull requests must be accompanied by passing automated tests (npm test).

See CONTRIBUTING.md guidelines

Changelog

See changelog

License

This project is licensed under the MIT License - see the LICENCE.md file for details

2.0.2

5 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago