Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chart crashes when only min is defined #9717

Closed
kurkle opened this issue Oct 4, 2021 · 0 comments · Fixed by #9718
Closed

Chart crashes when only min is defined #9717

kurkle opened this issue Oct 4, 2021 · 0 comments · Fixed by #9718
Milestone

Comments

@kurkle
Copy link
Member

kurkle commented Oct 4, 2021

    var chart = window.acquireChart({
      type: 'line',
      data: {
        datasets: [{
          data: [200]
        }],
      },
      options: {
        scales: {
          y: {
            min: 250
          }
        }
      }
    });

    expect(chart.scales.y.min).toBe(250);
    RangeError: minimumFractionDigits value is out of range.
      at new NumberFormat (<anonymous>)
       at getNumberFormat (src/chart.js:2822:17)
       at formatNumber (src/chart.js:2828:10)
       at LinearScale.numeric (src/chart.js:4589:12)
       at callback (src/chart.js:802:15)
       at LinearScale.generateTickLabels (src/chart.js:5145:20)
       at LinearScale._convertTicksToLabels (src/chart.js:5298:8)
       at LinearScale.update (src/chart.js:5055:8)
       at fitBoxes (src/chart.js:2144:9)
       at Object.update (src/chart.js:2280:5)

Both cases are fixed by making sure min <= max in the getMinMax of core.scale

    // Make sure min <= max when only min or max is defined by user and the data is outside that range
    min = maxDefined && min > max ? max : min;
    max = minDefined && min > max ? min : max;

    return {
      min: finiteOrDefault(min, finiteOrDefault(max, min)),
      max: finiteOrDefault(max, finiteOrDefault(min, max))
    };

Originally posted by @kurkle in #9641 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants