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] Incorrect position of image when using with pointBackgroundColor

See original GitHub issue

Expected Behavior

The picture should start rendering from the left top position of the point and should fill up the point. image

Current Behavior

The picture starts rendering from the centre of the point. image

Possible Solution

I am not sure about where the problem is, but the following change worked for me.

Add the following line after https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.canvas.js#L75

ctx.translate(-1 * radius, -1 * radius);

Steps to Reproduce (for bugs)

Here is a sample codepen that demonstrates the problem: https://codepen.io/anon/pen/aRgjwz

Context

I want to place the user avatars on the graph data points as can see in the expected behavior.

Environment

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nagixcommented, Nov 14, 2018

You may want to use chartjs-plugin-datalabels for text labels. You can also take the same approach as above like this.

tCtx.textAlign = "center";
tCtx.textBaseline = "middle"; 
tCtx.fillText("AB", 0, 0);
tCtx.fillText("AB", size, 0);
tCtx.fillText("AB", 0, size);
tCtx.fillText("AB", size, size);

var ctx = canvas.getContext("2d");
var fillStyle = ctx.createPattern(tempCanvas, "repeat");
1reaction
rajkumar-osmcommented, Nov 9, 2018

@nagix Thank you for the quick response.

I’ve tried pattern with offset and with repeat, now the picture seems to be aligned to the center, but it is not visible completely. Please check https://codepen.io/anon/pen/PxzYLj

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - why tooltip appears wrong in my chart JS? - Stack Overflow
I have a chart that I have developed using Chart JS and it works good. ... So for example in the image below,...
Read more >
Images with different align parameters display in incorrect ...
Bug CONFSERVER-18762 - Images with align tags are automatically indented as if they were ... The images display in incorrect order/position.
Read more >
Smarty - Kaburi
Simple HTML5 Charts using the canvas tag. https://github.com/chartjs/Chart.js; License: MIT. HINT! Use Smarty Colorpicker to get RGBA colors for your graphs!
Read more >
IE CSS bugs when using floats and background-color
If a div is given a background colour and contains floated items (floated using CSS's float or HTML 's align on images), things...
Read more >
[Solved]-How can I color dots in a xy scatterplot according to column ...
There is an Excel add-in called Funfun that allows you to use javascript, ... the scatter chart with each dot having his designated...
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