• Stars
    star
    110
  • Rank 314,877 (Top 7 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 8 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Animated SVG charts for React

React SVG chart

Animated SVG charts for React.

3.9kb gzipped.

Polyfill generators

However, you're currently also going to have to bring babel polyfill to the party at an additional 30.8kb gzipped. This is to support Javascript generators which a dependency of this library makes use of.

Examples

Line chart example

View line chart example code

Bar chart example

View bar chart example code

Installation

npm install react-svg-chart

Usage

Bar chart

import React from 'react';
import { BarChart } from 'react-svg-chart';

const App = () => (
  <BarChart
    bars={[
      { label: 'travel', value: 11 },
      { label: 'accomodation', value: 27 },
      { label: 'food', value: 4 },
      { label: 'drink', value: 19 },
      { label: 'tourism', value: 10 },
    ]}
    height={ 400 }
    width={ 600 }
  />
);

Line chart

import React from 'react';
import { LineChart } from 'react-svg-chart';

const App = () => (
  <LineChart
    lines={[
      { points: [
        { label: 'travel', value: 11 },
        { label: 'accommodation', value: 27 },
        { label: 'food', value: 4 },
        { label: 'drink', value: 19 },
        { label: 'tourism', value: 10 },
      ]},
    ]}
    height={ 400 }
    width={ 600 }
  />
);

CommonJS

This is how you get to the good stuff if you're using require.

const ReactSVGChart = require( 'react-svg-chart' );
const BarChart = ReactSVGChart.BarChart;
const LineChart = ReactSVGChart.LineChart;

UMD

And if you just want to smash in a Javascript file you're also covered. Drop this in place ...

https://unpkg.com/[email protected]/dist/react-svg-chart.min.js

Then access it on the ReactSVGChart global variable.

const BarChart = ReactSVGChart.BarChart;
const LineChart = ReactSVGChart.LineChart;

Props

BarChart

  • bars – required – an array of bar objects (each object should contain a label and a value)
  • barSpacing – the length between each bar
  • className – the SVG class
  • description – the SVG description
  • duration – the duration in milliseconds of the animation on data change
  • easing – the name of the easing function to use for the animation on data change
  • formatValue – the function to format the bar values for display
  • height – the SVG height
  • labelSpacing – the length between a label and the y-axis
  • labelWidth – the width to the left of the y-axis
  • preserveAspectRatio – the SVG preserveAspectRatio value
  • showLabels – show / hide labels
  • title – the SVG title
  • valueSpacing – the length between the value and the end of a bar
  • width – the SVG width

LineChart

  • className – the SVG class
  • description – the SVG description
  • duration – the duration in milliseconds of the animation on data change
  • easing – the name of the easing function to use for the animation on data change
  • formatValue – the function to format the bar values for display
  • height – the SVG height
  • labelHeight – the label height
  • labelOffset – the length between the center of a label and the x-axis
  • lines – required – an array of line objects (each object should contain a points array)
  • pointSize – the points diameter
  • preserveAspectRatio – the SVG preserveAspectRatio value
  • showLabels – show / hide labels
  • title – the SVG title
  • valueBorderRadius – the border-radius of the value background
  • valueHeight – the value height
  • valueOffset – the length between the center of a point and the center of it's value
  • valueWidth – the value width
  • width – the SVG width

Help make this better

Issues and pull requests gratefully received!

I'm also on twitter @colinmeinke.

Thanks 🌟

License

ISC.

More Repositories

1

ghost-storage-adapter-s3

An AWS S3 storage adapter for Ghost
JavaScript
182
star
2

wilderness

An SVG animation API
JavaScript
154
star
3

svg-points

A specification for storing SVG shape data in Javascript, and some handy conversion functions
JavaScript
98
star
4

svg-tween

Animate between SVG shapes
JavaScript
79
star
5

svg-arc-to-cubic-bezier

A function that takes an SVG arc curve as input, and maps it to one or more cubic bezier curves
JavaScript
75
star
6

universal-js

A universal Javascript starter kit inc. React, Redux, Redux Dev Tools, Universal Redux Router, CSS Modules, hot module reloading, Babel for ES2015+ and ESLint
JavaScript
66
star
7

points

A specification for storing shape data in Javascript, and some handy manipulation functions
JavaScript
44
star
8

universal-redux-router

A router that turns URL params into first-class Redux state and runs action creators on navigation
JavaScript
22
star
9

wilderness-dom-node

A set of functions to convert between SVG DOM nodes, Plain Shape Objects and Frame Shapes
JavaScript
14
star
10

css-modules-universal-example

An example of how to set up CSS modules with Webpack
JavaScript
13
star
11

svg-shapes

Get point data from SVG shapes. Convert point data to an SVG path
JavaScript
10
star
12

tweening

A little tweening library
JavaScript
4
star
13

wilderness-core

The SVG animation engine behind Wilderness
JavaScript
4
star
14

package

A quick start JS package template
JavaScript
4
star
15

wilderness-react

A React API for building and animating SVG
3
star
16

wilderness-docs

Wilderness documentation
JavaScript
2
star
17

consent.js

A simple Javascript API to ask for and store consent
JavaScript
2
star
18

tweening-color-middleware

Color middleware for tweening
JavaScript
2
star
19

wordz

JavaScript
1
star
20

yasmineawwad

JavaScript
1
star
21

docs

Front-end development documentation
1
star
22

hello-github-actions

1
star
23

goodidea

List and rank your ideas
Vue
1
star
24

meinke

Graham's website
HTML
1
star
25

colinmeinke

Personal website / playground
HTML
1
star
26

holmbank

Dad's website
JavaScript
1
star
27

oaxaca-syntax-theme

A minimal syntax theme for Atom
CSS
1
star
28

tienda-docs

Documentation site for Tienda – an ecommerce plugin for Craft CMS
HTML
1
star
29

postcss-calc-function

A PostCSS plugin to resolve the CSS calc function
JavaScript
1
star
30

theyvoteforyou

They want you to vote for them. But do they vote for you?
HTML
1
star
31

taxyear

Svelte
1
star
32

stupid-add-function

A stupid add function to test package
JavaScript
1
star
33

craft-react

Craft for content. React for UI.
PHP
1
star
34

www-https-redirect

A simple express server for www > https redirects
JavaScript
1
star