Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Rendering issue for Background color (Gradient and Opacity for solid color)

Open dinorahto opened this issue 2 years ago • 15 comments

Expected behavior

We are expecting Charts (Line Charts) with a solid background color that doesn't blink when getting filled out by the color

Example of expected look inside our views (we were expecting a gradient, but we switch it to a solid color) Screenshot 2023-05-25 at 12 53 31 p m

Current behavior

Using the next configuration for our dataSets:

const datasets = [ { label: 'Total', data: subtotalAmountData, fontColor: '#6B7280', pointBackgroundColor: '#1C64F2', pointBorderColor: '#1C64F2', fill: 'start', pointRadius: 3, backgroundColor: 'rgba(28, 100, 242, 0.5)', borderColor: 'rgba(28, 100, 242)', }, ];

We are seeing that our charts are looking with a little lag in the rendering, last for a second, and once the user scroll or clicks on it is gone

Screenshot 2023-05-25 at 12 55 23 p m Screenshot 2023-05-25 at 12 55 19 p m Screenshot 2023-05-25 at 12 53 31 p m

Reproducible sample

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgYQBYENZwL5wGZQQhwDkAxhrAHQBWAziQNwCwAUGwG6ZxkwAecALxwAJhDIBXEAFMAdjCoBzaTACiAG2kz5AIQCeASREAKAEQg9aTDFMBKOOjpwAEgBUAsgBlk6WVzoaWnIwLKxcUHAWVljCstIA7iiUMMa8fAA0iGxwOXAwemDSAFyk6sBxJOnZuSLoMOglCNW5ueroAEbS6nQlANqmAErSIqaZpjrqEtKjcKYAml3qEPEzpgDiUNJyqwAKElBgmqsA8lC+yqYAulWsLS219XQqPXC9Tbd3n22d6iUkAMRwCB4OAANQgMGkDBun0+DwarwAjAAmTKIgCcmQAzJkAKyZVFwLHXZp3bCXUnYGG5CBgGDACCyF7vT50MjoTTM0ktPiNbl3fk5KmCuB6PkfWFwEXYfkyiU4NjYWyMIAa

Optional extra steps/info to reproduce

No response

Possible solution

No response

Context

No response

chart.js version

^5.2.0

Browser name and version

react-chartjs-2

Link to your project

No response

dinorahto avatar May 25 '23 17:05 dinorahto

Chart.js does not have a version 5.2, current max version is 4.3.0.

But from your screenshots that looks like a rendering issue in chrome, seems verry similiar to another issue where it was like that. But it is hard to confirm without a reproducible sample

LeeLenaleee avatar May 25 '23 17:05 LeeLenaleee

I'm experiencing the same issue with a gradient. I noticed that it happens in Chrome, but NOT in Safari.

Chart.js v3.9.1. Chrome v114.0.5735.106 (Official Build) (arm64) Safari v16.5 (18615.2.9.11.4)

Here are screenshots from Chrome:

Screenshot 2023-06-19 at 12 23 32 Screenshot 2023-06-19 at 12 26 50

RobinTail avatar Jun 19 '23 10:06 RobinTail

Seems to be the duplicate of https://github.com/chartjs/Chart.js/issues/10727

RobinTail avatar Jun 19 '23 10:06 RobinTail

It seems that the issue comes from the growing line animation. When its shape is rising from the bottom it may leave those gaps.

I can confirm that it's possible to resolve the issue by setting { animation: false } config option. However, it does not feel as cool as before. Consider it as a temporary solution.

RobinTail avatar Jun 19 '23 11:06 RobinTail

Perhaps, there is a way to adjust the default animation to avoid that painting issue on Chrome. Please let me know if you tried something like that.

RobinTail avatar Jun 19 '23 11:06 RobinTail

Good news.

Perhaps the issue can be resolved by changing the setting the animation.easing to easeInElastic (while keeping the standard 1000 of the duration).

However, the animation itself is a bit weird for charts :)

Here are the results of my experiment.

animation.easing Outcome
easeOutQuart (default) easeOutQuart
linear linear
easeOutQuint easeOutQuint
easeOutCirc easeOutCirc
easeInOutQuint easeInOutQuint
easeInOutElastic easeInOutElastic
easeInCirc easeInCirc
easeInQuad easeInQuad
easeInExpo easeInExpo
easeInElastic easeInElastic

RobinTail avatar Jun 19 '23 11:06 RobinTail

I'm also facing the issue. is there any solution?

comictvn avatar Jul 08 '23 14:07 comictvn

@comictvn likely nothing that will work for everyone. This is likely a rendering problem inside the browser. I know that chrome used to switch between hardware and software rendering around a canvas size of 256x256px. Does the bug reproduce for you when the canvas is both small and large?

etimberg avatar Jul 08 '23 15:07 etimberg

@etimberg thank you! disabling animation is a temporary solution for now. the issue is happening even small and big size of canvas.

comictvn avatar Jul 08 '23 16:07 comictvn

Turning off animations didn't work

Enes5519 avatar Aug 02 '23 05:08 Enes5519

I know this won't work for everyone's use case, but I was able to fix it reliably at multiple screen sizes by removing the tension setting. I previously had tension: 0.1

I was also able to get it to work by setting maintainAspectRatio back to true, but that wasn't a good option for my use case because I have a fixed height.

leovolving avatar Sep 08 '23 18:09 leovolving

Also seeing this issue in Chrome, turning off tension works, but I would like to be able to use smoother curves.

With tension: image

Without tension: image

Changing easing function or turning off animations did not work for me.

midthun avatar Feb 03 '24 09:02 midthun

In my case, it occurs when it is approximately 330px or more.

unhyif avatar May 26 '24 08:05 unhyif