1 | # Beautiful and expressive sparklines component for React
|
2 |
|
3 | [![Build Status](https://travis-ci.org/borisyankov/react-sparklines.svg?branch=master)](https://travis-ci.org/borisyankov/react-sparklines)
|
4 |
|
5 | Live demos and docs: [borisyankov.github.io/react-sparklines/](http://borisyankov.github.io/react-sparklines/)
|
6 |
|
7 | ![](http://borisyankov.github.io/react-sparklines/img/dynamic.gif)
|
8 |
|
9 | ## Install
|
10 |
|
11 | ```
|
12 | npm install react-sparklines --save
|
13 | ```
|
14 |
|
15 | ## Run demo
|
16 |
|
17 | ```
|
18 | npm install
|
19 | npm start
|
20 | http://localhost:8080
|
21 | ```
|
22 |
|
23 |
|
24 | ## Use
|
25 |
|
26 | Import the Sparklines components that you need; for example to generate a simple chart:
|
27 |
|
28 | ![](http://borisyankov.github.io/react-sparklines/img/basic.png)
|
29 |
|
30 | ```
|
31 | import React from 'react';
|
32 | import { Sparklines } from 'react-sparklines';
|
33 | ...
|
34 | <Sparklines data={[5, 10, 5, 20, 8, 15]} limit={5} width={100} height={20} margin={5}>
|
35 | </Sparklines>
|
36 | ```
|
37 |
|
38 | Sparklines component is a container with the following properties:
|
39 |
|
40 | data - the data set used to build the sparkline
|
41 |
|
42 | limit - optional, how many data points to display at once
|
43 |
|
44 | width, height - dimensions of the generated sparkline in the SVG viewbox. This will be automatically scaled (i.e. responsive) inside the parent container by default.
|
45 |
|
46 | svgWidth, svgHeight - If you want absolute dimensions instead of a responsive component set these attributes.
|
47 |
|
48 | [preserveAspectRatio](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio) - default: 'none', set this to modify how the sparkline should scale
|
49 |
|
50 | margin - optional, offset the chart
|
51 |
|
52 | min, max - optional, bound the chart
|
53 |
|
54 |
|
55 | #### Basic Sparkline
|
56 |
|
57 | ![](http://borisyankov.github.io/react-sparklines/img/customizable.png)
|
58 |
|
59 | ```
|
60 | import React from 'react';
|
61 | import { Sparklines, SparklinesLine } from 'react-sparklines';
|
62 | ...
|
63 | <Sparklines data={[5, 10, 5, 20]}>
|
64 | <SparklinesLine color="blue" />
|
65 | </Sparklines>
|
66 | ```
|
67 |
|
68 | #### Bars
|
69 |
|
70 | ![](http://borisyankov.github.io/react-sparklines/img/bars.png)
|
71 |
|
72 |
|
73 | ```
|
74 | import React from 'react';
|
75 | import { Sparklines, SparklinesBars } from 'react-sparklines';
|
76 | ...
|
77 | <Sparklines data={[5, 10, 5, 20]}>
|
78 | <SparklinesBars />
|
79 | </Sparklines>
|
80 | ```
|
81 |
|
82 | #### Spots
|
83 |
|
84 | ![](http://borisyankov.github.io/react-sparklines/img/spots.png)
|
85 |
|
86 |
|
87 | ```
|
88 | import React from 'react';
|
89 | import { Sparklines, SparklinesLine, SparklinesSpots } from 'react-sparklines';
|
90 | ...
|
91 | <Sparklines data={sampleData}>
|
92 | <SparklinesLine style={{ fill: "none" }} />
|
93 | <SparklinesSpots />
|
94 | </Sparklines>
|
95 | ```
|
96 |
|
97 | #### Reference Line
|
98 |
|
99 | ![](http://borisyankov.github.io/react-sparklines/img/referenceline.png)
|
100 |
|
101 |
|
102 | ```
|
103 | import React from 'react';
|
104 | import { Sparklines, SparklinesLine, SparklinesReferenceLine } from 'react-sparklines';
|
105 | ...
|
106 | <Sparklines data={sampleData}>
|
107 | <SparklinesLine />
|
108 | <SparklinesReferenceLine type="mean" />
|
109 | </Sparklines>
|
110 | ```
|
111 |
|
112 | #### Normal Band
|
113 |
|
114 | ![](http://borisyankov.github.io/react-sparklines/img/normalband.png)
|
115 |
|
116 |
|
117 | ```
|
118 | import React from 'react';
|
119 | import { Sparklines, SparklinesLine, SparklinesNormalBand } from 'react-sparklines';
|
120 | ...
|
121 | <Sparklines data={sampleData}>
|
122 | <SparklinesLine style={{ fill: "none" }}/>
|
123 | <SparklinesNormalBand />
|
124 | </Sparklines>
|
125 | ```
|