Generates a Sparkline as an SVG.
npm install sparkline-svgGenerate a Sparkline as an SVG.
* npm install sparkline-svg or
* yarn add sparkline-svg
* Use
* d
* dataUri
* outerHTML
* setDecimals
* setDesc
* setDescription
* setFill
* setHeight
* setPreserveAspectRatio
* setStroke
* setStrokeWidth
* setTitle
* setValues
* setViewBoxHeight
* setViewBoxWidth
* setWidth
The sparkline-svg package exports a Sparkline class, which can be constructed with or without an array of values used to generate the sparkline.
``JavaScript
import Sparkline from 'sparkline-svg';
const sparkline= new Sparkline();
// or
const sparkline = new Sparkline(values);
`
sparkline.d returns the 's d attribute for the sparkline (stroke) itself.
sparkline.dataUri returns the sparkline SVG as a data URI, i.e. data:image/svg+xml;base64,.... This is particularly useful for CSS background images.
sparkline.outerHTML returns a string of the HTML for an SVG containing the sparkline.
Sets the number of decimal places used to generate the sparkline. A larger number of decimal places will result in better precision, but a larger file size.
_Default: 4_
Sets the description of the sparkline. Used to populate the element.
_Default: 'A line graph representation of a value\'s change over time.'_
Synonymous with setDesc.
Sets the color of the area underneath the sparkline.
_Default: 'transparent'_
Sets the height of the sparkline's SVG element. Not to be confused with setViewBoxHeight.
_Default: '100%'_
Sets the preserveAspectRatio attribute of the SVG element.
_Default: 'none'_
Sets the color of the sparkline itself.
_Default: 'currentColor'_
Sets the width of the sparkline itself. If using a number, this will be relative to the view box height and width.
_Default: '1%'_
Sets the title of the sparkline SVG by populating the
element. This is useful for accessibility purposes and often appears as a tooltip, similar to the title attribute on an anchor tag._Default: 'Sparkline'_
$3
Sets the values used to generate the sparkline. These can also be provided in the constructor.
_Default: []_
$3
Sets the height of the sparkline's view box. Not to be confused with
setHeight. The sparkline will always stretch to fit the view box._Default: 100_
$3
Sets the width of the sparkline's view box. Not to be confused with
setWidth. The sparkline will always stretch to fit the view box._Default: 100_
$3
Sets the width of the sparkline's SVG element. Not to be confused with
setViewBoxWidth`._Default: '100%'_