How to add different images (png, jpd or even webp) inside the point elements on scatter graphs? #11639
-
I tried by creating an array with dynamically added images, then writing in datasets the following: pointStyle = myArray I also tried this, saw it in a video tutorial: const pointImage = new Image(); then pointStyle = pointImage It didn't work. What am I doing wrong? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Have you watched this video: https://www.youtube.com/watch?v=lfHwnIk-JY8&t=209s&ab_channel=ChartJS If you did recheck your code and rewatch the video. You are missing something. I follow the video to see if it works on Chart.js Version 4 and it does nicely. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your replay, it works indeed :) But i'm struggling to do this with multiple and dynamically created images (from links). Creating multiple images "by hand" as shown in that video seems repetitive to me. Here is a more concrete example/pseudocode. the pointStyle option accepts an array with multiple images as Image() constructor, not with just links - this is the first lesson I've learned :) let imgArray = []; dataMockup.forEach (image => { The second lesson I learned is that you can't upload HTMLImageElement(s) into an array. Logging imgArray will show something like this [img, img, img] and, obviously(?), pointStyle = imgArray won't work. This happens in backend. Doing exactly the same thing in frontend (React / react-chartjs-2) will work and this bothers me :) |
Beta Was this translation helpful? Give feedback.
Thank you for your replay, it works indeed :) But i'm struggling to do this with multiple and dynamically created images (from links). Creating multiple images "by hand" as shown in that video seems repetitive to me.
Here is a more concrete example/pseudocode.
the pointStyle option accepts an array with multiple images as Image() constructor, not with just links - this is the first lesson I've learned :)
let imgArray = [];
let dataMockup = ['favicon1', 'favicon2', 'favicon3'];
dataMockup.forEach (image => {
let img = new Image (100, 100);
img.src =
https://www.chartjs.org/docs/3.5.1/${image}.ico
console.log(img) // "< i mg width="100" height="100" src="https://www.chartjs.org/docs/3.5.1/f…