npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-sparkline-chart

v0.4.0

Published

Simple SparkLine Chart with interactive tooltips, offering flexible customization options for effortless integration into any project.

Downloads

110

Readme

📈 Simple SparkLine Chart

A lightweight, customizable, and easy-to-use SparkLine chart library with tooltip and flexible options, written in TypeScript.

DEMO

CodePen 👀

Production 👀

Library

NPMJS 📦

UNPKG </>

GITHUB 🔮

🚀 Features

  • 🔥 Lightweight - Small footprint and blazing fast rendering.
  • 🎨 Customizable - Control colors, sizes, tooltips, and more.
  • 🎯 TypeScript Support - Fully typed for better development experience.
  • 📦 Multiple Formats - Available as CommonJS, ESModule, and a global script for easy CDN usage.

📦 Installation

Using npm:

npm install simple-sparkline-chart

Using CDN:

<script src="https://www.unpkg.com/simple-sparkline-chart"></script>

You can then use it via the global SimpleSparkLineChart:

<script>
  new SimpleSparkLineChart(".chart");
</script>

📚 Usage

1️⃣ Basic Example

<div
  class="sparkline"
  data-values="1,2,3,4,5,6,7"
  data-width="200"
  data-height="40"
></div>

<script>
  new SimpleSparkLineChart(".sparkline");
</script>

This will create a basic SparkLine chart using the specified data-values.

2️⃣ With Custom Options

<div
  class="sparkline"
  data-values="0.5,1.5,2.3,3.8,2.9,3.4"
  data-width="300"
  data-height="60"
  data-color-stroke="#00f"
  data-filled="0.3"
  data-tooltip="top"
  data-aria-label="My SparkLine Chart"
></div>

<script>
  new SimpleSparkLineChart(".sparkline");
</script>

🔧 Data Attributes

| Attribute | Type | Default | Description | | ------------------- | ------ | ------------------------ | -------------------------------------------------------------------------------------------------------------------- | | data-values | string | null (Required) | A comma-separated list of values or JSON data to plot. | | data-width | number | 200 | The width of the chart in pixels. | | data-height | number | Proportional to width | The height of the chart in pixels. Automatically calculated based on width, maintaining a proportional aspect ratio. | | data-color-stroke | string | #8956ff | The color of the chart line (stroke). | | data-filled | number | (none) | Defines the opacity of the fill area under the line if set. If not provided, no fill is displayed. | | data-tooltip | string | top | Tooltip position: "top" or "bottom". Tooltip is enabled if this attribute is set. | | data-aria-label | string | Simple SparkLine Chart | Accessible label for the chart. | | data-locale | string | User's locale | The locale used for formatting dates in tooltips (if using timestamp data). |

🧑‍💻 API

You can initialize the chart with the SimpleSparkLineChart constructor, and it automatically processes all matching elements.

Constructor

new SimpleSparkLineChart(selector: string);

  • selector: A CSS selector string to target the elements where the chart will be rendered.

🎨 Customization

You can customize the following:

  1. Stroke and Fill: Set your own colors for the line and the area below it with data-color-stroke and data-filled.
  2. Dimensions: Control the width and height of the chart using data-width and data-height.
  3. Tooltips: Enable or disable tooltips with data-tooltip, and adjust their position with data-tooltip-position.

📊 Example of Object Data

You can pass an array of objects with timestamps and values:

<div
  class="sparkline"
  data-values='[
        {"timestamp":1693526400000,"value":0.93},
        {"timestamp":1693612800000,"value":0.9315}
    ]'
  data-tooltip="top"
></div>

<script>
  new SimpleSparkLineChart(".sparkline");
</script>

🚀 Optimized for Performance

  • Minimized for production: The library is optimized to deliver minimal JS overhead.
  • Supports all modern browsers: Works in all major browsers including Chrome, Firefox, Safari, and Edge.

🔥 CDN Usage

For quick usage without installing npm dependencies:

<script src="https://www.unpkg.com/simple-sparkline-chart"></script>

🔧 Development

To build the project locally:

Install dependencies

npm install

Run the development server

npm start

Build the project

npm run build

Run tests

npm run test

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

💬 Feedback and Contributions

Feel free to open an issue if you find a bug or have a feature request. Pull requests are welcome! 🙌

Hope you enjoy using Simple SparkLine Chart! 🚀✨