GoogleWebComponents / google-chart

Google Charts API web components
https://www.webcomponents.org/element/@google-web-components/google-chart/elements/google-chart
Apache License 2.0
358 stars 130 forks source link

No way of specifying mapsApiKey for using geoChart #197

Closed malthusyau closed 5 years ago

malthusyau commented 7 years ago

For the geoChart, there is no way to include the mapsApiKey on google.charts.load. Like the example here: https://developers.google.com/chart/interactive/docs/basic_load_libs#load-settings

wesalvaro commented 7 years ago

I believe this bug may have the solution for you: https://github.com/google/google-visualization-issues/issues/2292

Specifically, it seems you should just be able to set: google.visualization.mapsApiKey = YOUR_MAPS_KEY; before drawing your chart.

djbecky commented 7 years ago

I see there is a attribute named api-key in google-map, user could pass Google Maps Key to it. Is it valuable to add this feature into google-chart?

wesalvaro commented 7 years ago

@djbecky Yes, it probably is. I think we would just want to add an "options" type attribute to the loader element to allow users to specify their own options in a straight-forward Object fashion. Since there is a work-around, I'd rather keep it the way it is at-the-moment and think about it a little more, adding it to the v2 update.

djbecky commented 7 years ago

@wesalvaro For now, I see google-chart only support three events (google-chart-select, google-chart-ready and selection-changed), I could not find the good time to set my API key before drawing.

wesalvaro commented 7 years ago

Correct, you don't want to listen to the chart, but to the loader.

The loader will fire a loaded event (which should really be google-charts-loaded but alas...) which you can observe and then update your mapsApiKey as in this fiddle I created.

You can comment out the API key assignment line and see an error appear in the console about the lack of an API key. I'm not super familiar with the geochart, but it seems using the top level google-chart-loader element should solve the problem.

rslawik commented 5 years ago

mapsApiKey can be passed to the load function introduced in #245 together with other settings. custom-load-test has an example. load still needs to be called before any chart is rendered.