Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ycsm's avatar
Level 1

Laravel Charts - Trying to change ChartJS data dynamically fails

I'm using Laravel 6, Laravel Charts along with ChartJS. I have succesffully rendered a chart.

Laravel gives it a random unique ID each time the page is loaded.

I get it like so:

{{ $pieGenderChart->id }}

I wan't to change some of the dataset dynamically so I've looked into the DOM with

console.log(window);

Here's my chart (I believe)

enter image description here

I want to be able to change the data in the dom like so:

window.{{ $pieGenderChart->id }}.config.data.datasets[0].data[0] = x

It sits in the root of window... so I should be able to call it like so, right?

console.log(window.{{ $pieGenderChart->id }}); 
console.log(getElementById({{ $pieGenderChart->id }}));

Either way, same with JQuery, I only get the following

enter image description here

What am I missing here?

0 likes
2 replies
andreicozma's avatar

I think you have the same id for canvas and for parent element. You want to select the parent element. Try console.log(getElementById({{ $pieGenderChart->id }}).parentNode); and see if it's working

Please or to participate in this conversation.