Skip to content

Commit

Permalink
Added fill possibility for trendline
Browse files Browse the repository at this point in the history
(cherry picked from commit d9fec4e)
  • Loading branch information
igor90 authored and Makanz committed Aug 23, 2022
1 parent dcd39b8 commit 3524b7d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/chartjs-plugin-trendline.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function addFitter(datasetMeta, ctx, dataset, xScale, yScale) {
var colorMax = dataset.trendlineLinear.colorMax || defaultColor;
var lineWidth = dataset.trendlineLinear.width || dataset.borderWidth;
var lineStyle = dataset.trendlineLinear.lineStyle || 'solid';
var fillColor = dataset.trendlineLinear.fillColor;

lineWidth = lineWidth !== undefined ? lineWidth : 3;

Expand Down Expand Up @@ -140,6 +141,18 @@ function addFitter(datasetMeta, ctx, dataset, xScale, yScale) {
ctx.strokeStyle = gradient;

ctx.stroke();
ctx.closePath();

if (!!fillColor) {
ctx.fillStyle = fillColor;
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.lineTo(x2, drawBottom);
ctx.lineTo(x1, drawBottom);
ctx.closePath();
ctx.fill();
}
}

function LineFitter() {
Expand Down

0 comments on commit 3524b7d

Please sign in to comment.