Skip to content

Commit

Permalink
Solve problem when data object contains both numbers and strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Makanz committed May 23, 2023
1 parent 8795c5b commit 2a434ca
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/chartjs-plugin-trendline.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ function addFitter(datasetMeta, ctx, dataset, xScale, yScale) {
var x = data.x != null ? data.x : data.t;
fitter.add(new Date(x).getTime(), data.y);
} else if (xy) {
fitter.add(data.x, data.y);
if (!isNaN(data.x) && !isNaN(data.y)) {
fitter.add(data.x, data.y);
} else if (!isNaN(data.x)) {
fitter.add(index, data.x);
} else if (!isNaN(data.y)) {
fitter.add(index, data.y);
}
} else {
fitter.add(index, data);
}
Expand Down

0 comments on commit 2a434ca

Please sign in to comment.