1.0.0 • Published 1 year ago

magx-sparkline v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Magx-Sparkline

Sparkline is a very plain and usually smallish chart that is used to show a variation in a measurement. It is used for providing a quick-glance and simple information without extra bells and whistles.

Magx-Sparkline uses Lit as the base libray for creating the web components and Vite as the build tool.

Examples

See the index.html and main.ts files that show various different sparkline examples.

How To Use

Install the component using npm:

$ npm install magx-sparkline

View the examples:

$ npm run dev

Then connect on your browser to the localhost URL provided by Vite.

First create either instance of MagxSparkline class or declare <magx-sparkline> element in DOM. If you declare the element in DOM, you can define multiple different attributes to customize the sparkline. Similarly you can customize the component completely programmatically.

The key values to changes are the type of the sparkline (line chart / bar chart), the outlook of the line and filling, and the reference line y-position and outlook that defines, which values are over/under zero line.

New data can be added dynamically and the total amount of data points on the sparkline can be defined at will.

The key attributes to modify are:

AttributeMethod on classHTML Attribute
Sparkline typesetType()type
Background colorsetBackgroundColor()bckgCol
Line / bar outline widthsetLineWidth()lineWidth
Line / bar type and color(s)setLineColor()lineType, lineColor, lineAboveCol, lineBelowCol
Fill color between reference line and sparklinesetFill()fillType, fillCol, fillAboveCol, fillBelowCol
Reference line typesetReferenceLine()refLineType, refLineYPos
Reference line widthsetReferenceLineWidth()refLineWidth
Reference line colorsetReferenceLineColor()refLineColor
Endpoint marker color and radiussetEndpoint()endpointCol, endpointRadius
Set lower bound limitsetLowerBound()lowerBound
Set upper bound limitsetUpperBound()upperBound
Cap values on lower boundsetCap()capBelow
Cap values on upper boundsetCap()capAbove
Set datasetDataPointNum(), addDatapoint(), setData()data