npm/sparkline

Name: sparkline

Owner: npm

Description: Generate SVG sparklines with JavaScript without any external dependency.

Created: 2018-02-22 19:52:32.0

Updated: 2018-02-26 02:42:41.0

Pushed: 2018-02-22 19:57:53.0

Homepage:

Size: 473

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

sparkline

Generate SVG sparklines with JavaScript without any external dependency.

Instalation

This lib is available as a NPM package. To install it, use the following command:

install @fnando/sparkline --save

If you're using Yarn (and you should):

 add @fnando/sparkline

You'll have to call sparkline.sparkline(svg, values, options) directly if you're loading the script without compiling your script (e.g. webpack). Otherwise you can simply import sparkline from "@fnando/sparkline";.

API
sparkline(svg, values, options = {})
Usage

This is the minimum working example:

 width, height and stroke-width attributes must be defined on the target SVG -->
 class="sparkline" width="100" height="30" stroke-width="3"></svg>

ipt>
arkline(document.querySelector(".sparkline"), [1, 5, 2, 4, 8, 3, 7]);
ript>

You can change the colors by either setting the attributes directly to the SVG element or using CSS, like the following:

ust the line */
rkline {
roke: red;
ll: none;


ine with highlight area */
rkline {
roke: red;
ll: rgba(255, 0, 0, .3);


hange the spot color */
rkline--spot {
roke: blue;
ll: blue;


hange the cursor color */
rkline--cursor {
roke: orange;

Examples
Static

Available at https://codepen.io/fnando/full/KyZLLV/

Interactive

Available at https://codepen.io/fnando/full/GOQLVE/

License

(The MIT License)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.