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 🙏

© 2025 – Pkg Stats / Ryan Hefner

chartjs-plugin-trendline

v3.2.0

Published

Trendline for Chart.js

Downloads

128,714

Readme

chartjs-plugin-trendline

This plugin draws linear and exponential trendlines in your Chart. It has been tested with Chart.js version 4.4.9.

📊 View Live Examples

See the plugin in action with interactive examples for different chart types.

Installation

Note: Version 3.2.0+ supports ES modules (ESM) for modern bundlers like Vite, SvelteKit, and Next.js. See MIGRATION.md for upgrade details.

Modern Bundlers (Vite, SvelteKit, Next.js, webpack 5+)

Install via npm:

npm i chart.js chartjs-plugin-trendline

Import and register with Chart.js:

import { Chart } from 'chart.js';
import ChartJSTrendline from 'chartjs-plugin-trendline';

Chart.register(ChartJSTrendline);

Node.js (CommonJS)

const { Chart } = require('chart.js');
const ChartJSTrendline = require('chartjs-plugin-trendline');

Chart.register(ChartJSTrendline);

Browser (CDN)

Load Chart.js first, then the plugin which will automatically register itself:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline/dist/chartjs-plugin-trendline.min.js"></script>

The plugin is now available globally as ChartJSTrendline and auto-registers with Chart.js.

Configuration

To configure the trendline plugin you simply add a new config options to your dataset in your chart config.

Linear Trendlines

For linear trendlines (straight lines), use the trendlineLinear configuration:

{
	trendlineLinear: {
		colorMin: Color,
		colorMax: Color,
		lineStyle: string, // "dotted" | "solid" | "dashed" | "dashdot"
		width: number,
		xAxisKey: string, // optional
		yAxisKey: string, // optional
		projection: boolean, // optional
		trendoffset: number, // optional, if > 0 skips first n elements, if < 0 uses last n elements
		// optional
		label: {
			color: Color,
			text: string,
			display: boolean,
			displayValue: boolean, // shows slope value
			offset: number,
			percentage: boolean,
			font: {
				family: string,
				size: number,
			}
		},
		// optional
		legend: {
			text: string,
			strokeStyle: Color,
			fillStyle: Color,
			lineCap: string,
			lineDash: number[],
			lineWidth: number,
		}
	}
}

Exponential Trendlines

For exponential trendlines (curves of the form y = a × e^(b×x)), use the trendlineExponential configuration:

{
	trendlineExponential: {
		colorMin: Color,
		colorMax: Color,
		lineStyle: string, // "dotted" | "solid" | "dashed" | "dashdot"
		width: number,
		xAxisKey: string, // optional
		yAxisKey: string, // optional
		projection: boolean, // optional
		trendoffset: number, // optional, if > 0 skips first n elements, if < 0 uses last n elements
		// optional
		label: {
			color: Color,
			text: string,
			display: boolean,
			displayValue: boolean, // shows exponential parameters (a, b)
			offset: number,
			font: {
				family: string,
				size: number,
			}
		},
		// optional
		legend: {
			text: string,
			strokeStyle: Color,
			fillStyle: Color,
			lineCap: string,
			lineDash: number[],
			lineWidth: number,
		}
	}
}

Note: Exponential trendlines work best with positive y-values. The equation fitted is y = a × e^(b×x), where:

  • a is the coefficient (scaling factor)
  • b is the growth rate (positive for growth, negative for decay)

Examples

Supported chart types

  • bar
  • line
  • scatter

Both linear and exponential trendlines are supported for all chart types.

Contributing

Pull requests and issues are always welcome. For bugs and feature requests, please create an issue.

License

chartjs-plugin-trendline.js is available under the MIT license.

Star History

Star History Chart