question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`new Chart` throws `RangeError: minimumFractionDigits value is out of range.`

See original GitHub issue

Expected Behavior

Should work normally

Current Behavior

Throws an error RangeError: minimumFractionDigits value is out of range. from new Chart(...). This is the same as #9019 which was already closed.

It happens when occasionally, and calculateLabelRotation gets a NaN value. This happens when Math.asin(Math.min(maxHeight / maxLabelDiagonal, 1)) is NaN, as you cannot Math.asin on a value less than -1. This issue propagates into NaN margins and messes up everything until the next update call.

Possible Solution

The constraint should be Math.max(Math.min(maxHeight / maxLabelDiagonal, 1), -1). Adding the Math.max(..., -1) here fixes it. The fix is easy, and mathematically correct, as the range for asin is -1 to 1.

Steps to Reproduce

I actually had a hard time reproducing this. This happens ocassionally but not consistently, with a line (time series) chart, and the canvas not being in the dom yet. Although the canvas has a default size of 300x150 to specs. I’m sorry I can’t throw in here a codepen that shows the issue. I guess this has to do with lots of environmental parameters, perhaps including the current time.

Context

Environment

  • Chart.js version: 3.4.1
  • Browser name and version: Chrome 91.0.4472.124

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8

github_iconTop GitHub Comments

11reactions
jayantbhcommented, Sep 30, 2022

This is for nextjs

@brixbimboavengoza’s comment stopped the error for me, but the y axis only showed one tick (the topmost one), which wasn’t usable to me.

Turns out, based on @kurkle’s comment here, you can turn off swcMinify to fix this.

Problem is, swcMinify: true reduces my build time by almost half. And I didn’t want to let that go.

I took a bit of a risk and changed the next version to the latest canary (15 as of now) as of today and that fixed it just fine! As of 12.3.2 canary 10, the swc minifier version was updated which included the fix.

4reactions
brixbimboavengozacommented, Sep 21, 2022

``> I still got this kind of error in version 3.9.1

try this scale: { y: { ticks: { callback: function (val, index) { return '${this.getLabelForValue(Number(val))}%'; }, } } }

Read more comments on GitHub >

github_iconTop Results From Across the Web

minimumFractionDigits value is out of range" with ChartJS in ...
The problem was I was using v3.1 Chart.js, while trying to use settings from ... RangeError: minimumFractionDigits value is out of range.
Read more >
RangeError: precision is out of range - JavaScript | MDN
The JavaScript exception "precision is out of range" occurs when a number that's outside of the range of 0 and 20 (or 21)...
Read more >
minimumFractionDigits value is out of range in Chart.js-Chart.js
Coding example for the question Adding X axis title causes Uncaught RangeError: minimumFractionDigits value is out of range in Chart.js-Chart.js.
Read more >
[Value number out of range for numberformat options property ...
The error basically means that you are assigning an incorrect value to the Style attribute --> "number". As per the documentation, ...
Read more >
nextjs a client-side exception has occurred - You.com | The Search ...
Off. Moderate. Strict. Open links in a new tab ... .com/troubleshoot/resolved-rangeerror-minimumfractiondigits-value-is-out-of-range-chart-js-45187/.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found