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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@stklcode/chartist-plugin-tooltips

v2.0.0

Published

Tooltips Plugin for Chartist.js

Readme

Tooltips for Chartist

npm

This plugin provides quick and easy tooltips for your Chartist charts. It's published on npm as @stklcode/chartist-plugin-tooltips.

Configuration Options

The following options can be configured when the plugin is loaded. Their default values are as shown.

const defaultOptions = {
  // Tooltip offset in pixels
  tooltipOffset: { x: 0, y: -20 },

  // Custom function to generate tooltip HTML ( (meta, value) => html )
  tooltipFnc: undefined,

  // Custom function to generate tooltip text ( value => text )
  transformTooltipTextFnc: undefined,

  // Add class(es) to the tooltip wrapper (string or array of strings)
  class: undefined,

  // If true, the tooltips will not follow mouse movement and be anchored to the target point or bar
  anchorToPoint: false,

  // Appends tooltips to body instead of chart container.
  appendToBody: true,

  // Should the meta content be parsed as HTML?
  metaIsHTML: false,

  // Custom point class to append tooltips to (uses Chartist's default point class if not specified)
  pointClass: undefined
};

Sample Usage

1. Install the plugin

npm add @stklcode/chartist-plugin-tooltips

2. Including JavaScript

Include the JavaScript script file of the plugin either using one of two options:

  1. Include it using a <script> tag:
<script src="node_modules/chartist/dist/index.umd.js"></script>
<script src="node_modules/chartist-plugin-tooltip/dist/chartist-plugin-tooltip.umd.js"></script>

<script>
  const chart = new Chartist.LineChart('.ct-chart', data, {
    plugins: [
      ChartistPluginTooltip
    ]
  });
</script>
  1. Include it using an import:
import { LineChart } from 'chartist';
import ChartistPluginTooltip from '@stklcode/chartist-plugin-tooltips';

const chart = new LineChart('.ct-chart', data, {
  plugins: [
    ChartistPluginTooltip
  ]
});

3. Include CSS

Include the two CSS files in your project:

  • node_modules/chartist/dist/index.css
  • node_modules/@stklcode/chartist-plugin-tooltips/dist/chartist-plugin-tooltip.css

Either using one of two options:

  1. Include them in the <head> of your HTML file
<link rel="stylesheet" href="node_modules/chartist/dist/index.css">
<link rel="stylesheet" href="node_modules/@stklcode/chartist-plugin-tooltips/dist/chartist-plugin-tooltip.css">
  1. Include them as Webpack CSS imports
import 'chartist/dist/index.css';
import '@stklcode/chartist-plugin-tooltips/dist/chartist-plugin-tooltip.css';

4. Configure labels

Without custom metadata

const chart = new Chartist.LineChart('.ct-chart', {
  labels: [ 1, 2, 3, 4, 5, 6, 7 ],
  series: [
    [ 1, 5, 3, 4, 6, 2, 3 ],
    [ 2, 4, 2, 5, 4, 3, 6 ]
  ]
}, {
  plugins: [
    ChartistPluginTooltip
  ]
});

With a descriptive text:

const chart = new Chartist.LineChart('.ct-chart', {
  labels: [ 1, 2, 3 ],
  series: [
    [
      { meta: 'description', value: 1 },
      { meta: 'description', value: 5 },
      { meta: 'description', value: 3 }
    ],
    [
      { meta: 'other description', value: 2 },
      { meta: 'other description', value: 4 },
      { meta: 'other description', value: 2 }
    ]
  ]
}, {
  plugins: [
    ChartistPluginTooltip
  ]
});

With a custom formatted descriptive text:

const chart = new Chartist.LineChart('.ct-chart', {
  labels: [ 1, 2, 3 ],
  series: [
    [
      { meta: 'description', value: 1 },
      { meta: 'description', value: 5 },
      { meta: 'description', value: 3 }
    ],
    [
      { meta: 'other description', value: 2 },
      { meta: 'other description', value: 4 },
      { meta: 'other description', value: 2 }
    ]
  ]
}, {
  plugins: [
    [
      ChartistPluginTooltip,
      {
        transformTooltipTextFnc: (value) => `${value} $`,
        class: [ 'class1', 'class2' ],
        appendToBody: true
      }
    ]
  ]
});

If you change the CSS properties of the tooltip, you shouldn't change the display property, otherwise the tooltip may be incorrectly positioned.

Custom Point Element

This guide is a bit outdated and may not work with new versions of the plugin.

In Chartist, you can replace the default point element with a custom element. There is a pretty demo which uses events to replace the default point graphics. If you want the tooltip to work fine with a new element, you need to include two more properties to your custom element:

  'ct:value': data.value.y,
  'ct:meta':  data.meta,

And you have to add the following CSS rule to the new element by using the style option or by adding this rule to your css class:

pointer-events: all !important;

(If you want to read more about, why you have to add this css rule take a look at chartist-plugin-tooltip#72)

So the final code could look like this. Here is a live demo

chart.on('draw', (data) => {
  // If the draw event was triggered from drawing a point on the line chart
  if (data.type === 'point') {
    // We are creating a new path SVG element that draws a triangle around the point coordinates

    const circle = new Chartist.Svg('circle', {
      cx: [data.x],
      cy: [data.y],
      r: [5],
      'ct:value': data.value.y,
      'ct:meta': data.meta,
      style: 'pointer-events: all !important',
      class: 'my-cool-point',
    }, 'ct-area');

    // With data.element we get the Chartist SVG wrapper and we can replace the original point drawn by Chartist with our newly created triangle
    data.element.replace(circle);
  }
});
plugins: [
  [
    ChartistPluginTooltip,
    {
      appendToBody: true,
      pointClass: 'my-cool-point'
    }
  ]
]

Credits

This repository is a fork of "chartist-plugin-tooltip-updated" (lukbukkit/chartist-plugin-tooltip) which was itself a fork of the original "chartist-plugin-tooltips" (gionkunz/chartist-plugin-tooltip).

Many thanks to the authors and all contributors for their great work.

Both projects are no longer maintained. Please do not expect any major functional updates here either (PRs welcome though), mainly smaller maintenance updates to keep things running.