devstark-com / vue-google-charts

Reactive Vue.js wrapper for Google Charts lib
446 stars 73 forks source link

TypeError: Cannot read properties of undefined (reading 'load') #237

Open Arkk92 opened 1 year ago

Arkk92 commented 1 year ago

Since looks like no one is updating the module I'm writing this issue to whom may be interested in solving the error in the title:

Screenshot from 2023-07-07 12-29-11

I have faced this error using the Google Charts in my components, in fact it started happening when I added more than one chart in different components, so GChart was called more than once.

After digging in Google I couldn't find any solution so I read the Google documentation saying that google.chart.load shall be called only once at the begining. Since the module it's doing it by itself, I came out with a solution. I found that I we add the following line before mounting the App it was actually working fine and the error didn't show up.

import { loadGoogleCharts } from 'vue-google-charts'

loadGoogleCharts('current', { packages: ['corechart'] })

Since it looks like a usage problem more than package implementation problem, I would suggest to whoever that maintains the package to update README adding this information. I lost many hours trying to get rid of this issue.

rexdarelandig commented 1 year ago

jesus. thank you for this. I just added the code in my App.vue