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.

[BUG] Cannot read property 'r' of null

See original GitHub issue

Expected Behavior

It should avoid the exception or change the behavior when borderColor is null.

Current Behavior

Hi. I’m using the library with a server-side personalization data. I saw that when borderColor property is null and you put the mouse over a chart bar, an exception is thrown:

Uncaught TypeError: Cannot read property 'r' of null at Color (https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.js:269:11) at Color (https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.js:243:10) at Object.helpers.color (https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.js:10115:11) at Object.helpers.getHoverColor (https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.js:10122:12) at ChartElement.setHoverStyle (https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.js:6688:147) at Chart.updateHoverStyle (https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.js:8953:67) at Chart.handleEvent (https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.js:9036:8) at Chart.eventHandler (https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.js:8973:21) at listener (https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.js:8910:21) at HTMLCanvasElement.proxies.(anonymous function) (https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.js:15346:4)

Possible Solution

Well at this point: // parse Color() argument var vals; if (typeof obj === 'string') { vals = string.getRgba(obj); if (vals) { this.setValues('rgb', vals); } else if (vals = string.getHsla(obj)) { this.setValues('hsl', vals); } else if (vals = string.getHwb(obj)) { this.setValues('hwb', vals); } } else if (typeof obj === 'object') { vals = obj; if (vals.r !== undefined || vals.red !== undefined) { this.setValues('rgb', vals); } else if (vals.l !== undefined || vals.lightness !== undefined) { this.setValues('hsl', vals); } else if (vals.v !== undefined || vals.value !== undefined) { this.setValues('hsv', vals); } else if (vals.w !== undefined || vals.whiteness !== undefined) { this.setValues('hwb', vals); } else if (vals.c !== undefined || vals.cyan !== undefined) { this.setValues('cmyk', vals); } }

since Google Chrome evaluates typeof null === ‘object’, I would change the evaluation typeof obj === ‘object’ with: obj !== null && typeof obj === 'object'

Steps to Reproduce (for bugs)

Here is a live example: https://jsfiddle.net/4Ltajgq1

Context

At job, during development state, trying to get server data and set the chart with that data.

Environment

  • Chart.js version: 2.7.1
  • Browser name and version: Google Chrome 56.0.2924.87 (64-bit)
  • Link to your project: I can’t

Thank you so much

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
Seabizkitcommented, Mar 28, 2019

so this wasnt fixed. getting in 2.8

3reactions
etimbergcommented, Dec 28, 2017

@didix16 the issue is setting borderColor: null. If you want to remove the border from the bars, I would recommend using borderWidth: 0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read property of null - iDiallo
All this means is that you are trying to access a property of an object that is undefined. These usually happens when we...
Read more >
TypeError: Cannot read property 'sourceToRendered' of null ...
Error exception is thrown when HOT is within Angular Material Tab which is inactive (not visible). Demo: https://hot-tab-demo51.stackblitz.io
Read more >
TypeError: Cannot read properties of null (reading 'user')
Initially, in the first render, user state has a value null and thus user cant have a property. WHat you can do to...
Read more >
T32154 Uncaught TypeError: Cannot read property 'query' of ...
This bug doesn't seems to happen often, but I've noticed the following error after trying to ... Uncaught TypeError: Cannot read property 'query'...
Read more >
How to deal with Cannot read property 'destroy' of null using ...
The system is trying to use a property from an element that isn't in the screen. Have you elements in your screen that...
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