Skip to content

Commit

Permalink
Line Styles added / edited : Dotted, Dashed, DashDot, Solid
Browse files Browse the repository at this point in the history
  • Loading branch information
BryceSimtars committed Sep 13, 2024
1 parent 0065682 commit bc1da5f
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/chartjs-plugin-trendline.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,21 @@ const addFitter = (datasetMeta, ctx, dataset, xScale, yScale) => {

ctx.lineWidth = lineWidth;

if (lineStyle === 'dotted') {
ctx.setLineDash([2, 3]); // Dotted
} else {
ctx.setLineDash([]); // Solid
// line styles
switch (lineStyle) {
case 'dotted':
ctx.setLineDash([2, 2]); // Dotted
break;
case 'dashed':
ctx.setLineDash([8, 3]); // Dashed
break;
case 'dashdot':
ctx.setLineDash([8, 3, 2, 3]); // Dash-dot
break;
case 'solid':
default:
ctx.setLineDash([]); // Solid
break;
}

ctx.beginPath();
Expand Down

0 comments on commit bc1da5f

Please sign in to comment.