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

Bar chart has border artifacts

Open jq2dj opened this issue 4 years ago • 7 comments

Expected Behavior

Bar chart with borderWidth = 0 has no border. The bar itself should be a solid block of the chosen color. Bar chart with borderWidth > 0 should have a border in the chosen color, but no other lines/colors.

Current Behavior

Bar chart has some kind of border, when borderWidth = 0: Screenshot Border https://codepen.io/nwi4/pen/KKvOdbW

Bar chart has some other lines around the border, with borderWidth > 0: Screenshot Border 2 https://codepen.io/nwi4/pen/mdMNBJw

Are there some settings I am missing to tweak this behavior?

Context

When stacking multiple (small) bars on each other, the unwanted lines blur the edges and it looks more like a gradient than multiple distinct bars: Bar There are 2 big bars, and 3 very small bars, which looks like the fade out of the bigger one before.

Environment

  • Chart.js version: 3.6.0
  • Browser name and version: Chrome 96

jq2dj avatar Nov 26 '21 08:11 jq2dj

We also have this issue, and a related issue where if we have a borderWidth of 1 or 2 with an identical borderColor and backgroundColor, it becomes more pronounced, as though there's a 'ghost border'.

Screen Shot 2021-12-06 at 8 58 51 PM

If we add a much bigger borderWidth, it shows as a fine white line between the 'border' and 'backgroundColor'.

Screen Shot 2021-12-06 at 9 04 05 PM

alimirakim avatar Dec 07 '21 02:12 alimirakim

alignToPixels: true could help

kurkle avatar Dec 15 '21 21:12 kurkle

Thank you for your answer.

I updated the examples and this option helps a little, some unwanted lines are now gone, but some remain: Bars with alingToPixels

jq2dj avatar Dec 16 '21 08:12 jq2dj

Its called anti-aliasing and afaik can not be turned off (except for maybe some browsers).

https://stackoverflow.com/questions/195262/can-i-turn-off-antialiasing-on-an-html-canvas-element

kurkle avatar Dec 16 '21 09:12 kurkle

Oh, another thing you can do, set devicePixelRatio higher than your display has.

1 image

2 image

4 image

kurkle avatar Dec 16 '21 09:12 kurkle

Hi! Can I solve this issue as a good-first-issue? Is it hard or easy? Can anyone help me to solve it?

SMSadegh19 avatar Dec 23 '21 22:12 SMSadegh19

I see white artifacts when border disabled
How to solve this problem?
image
Example

Spirit04eK avatar May 17 '22 03:05 Spirit04eK

Seeing the same error as above with line charts

image

"chart.js": "^4.3.0",
    "chartjs-adapter-luxon": "^1.3.1",
    "chartjs-plugin-annotation": "^2.2.1",

huzaifahj avatar May 04 '23 06:05 huzaifahj