adminMongo icon indicating copy to clipboard operation
adminMongo copied to clipboard

Chart datapoint interpolation/tension is funky

Open jamesinc opened this issue 6 years ago • 2 comments

See this screenshot:

It seems like it's a known shortcoming of Chart.js's bezier function, but there are a couple of fixes written-up in the issue comments for charts where you have a known x-axis boundary (which as far as I've seen is always y=0 for adminMongo's charts).

https://github.com/chartjs/Chart.js/issues/424#issuecomment-51399997

jamesinc avatar Mar 06 '18 22:03 jamesinc

capBezierPoints doesn't work :(

makseq avatar Jun 18 '19 12:06 makseq

Setting tension: 0 took much of the aesthetic out so I edited the non-minified version of Chart.js v2.9.4

Find at at line 2498: ctx.bezierCurveTo( flip ? previous.controlPointPreviousX : previous.controlPointNextX, flip ? previous.controlPointPreviousY : previous.controlPointNextY, flip ? target.controlPointNextX : target.controlPointPreviousX, flip ? target.controlPointNextY : target.controlPointPreviousY, target.x, target.y); Edit to: if (previous.y == target.y) { ctx.lineTo(target.x, target.y); } else { ctx.bezierCurveTo( flip ? previous.controlPointPreviousX : previous.controlPointNextX, flip ? previous.controlPointPreviousY : previous.controlPointNextY, flip ? target.controlPointNextX : target.controlPointPreviousX, flip ? target.controlPointNextY : target.controlPointPreviousY, target.x, target.y); }

Basically checks start and end points. If they are on the same y height, just draw a straight line.

Fixed my issue from this: bezier_default

To this: bezier_flat

PropelNZ avatar Jan 20 '21 08:01 PropelNZ