Chart.js Plugin Trendline

Interactive examples showcasing linear trendline functionality for Chart.js

Quick Start

Add the plugin to your HTML page:

<script src="https://cdn.jsdelivr.net/npm/chart.js@4.6.1/dist/chart.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline/dist/chartjs-plugin-trendline.min.js"></script>

Bar Chart

Basic bar chart with dotted trendline

Bar Chart with Label

Bar chart displaying trendline with custom label

Bar Chart with Null Values

Handling datasets with missing data points

Line Chart

Standard line chart with linear trendline

Exponential Trendline

Exponential curve fitting on a logarithmic axis

Exponential on a Linear Axis

The same fit on an axis where the curve is visible

Line Chart Projection

Line chart with trendline projection beyond data

Time Series Line Chart

Line chart with time-based x-axis

Scatter Chart

Scatter plot with fitted trendline

Scatter Projection

Scatter chart with extended trendline projection

Custom Axis Keys

xAxisKey and yAxisKey on time-series data

Fill and Legend Toggle

fillColor, and alwaysShowTrendline when a series is hidden

Slope in Percent and Offset

percentage labels and trendoffset on a plain array