ChartWrapper won't automatically load Map packages

47 views
Skip to first unread message

Almania M

unread,
Apr 15, 2021, 1:23:35 AM4/15/21
to Google Visualization API
Hello,

According to the ChartWrapper docs, the ChartWrapper handles loading all necessary libraries. If you have third party libraries then you must load them yourself explicitly.
  • ChartWrapper claiming to handle lading of all libraries here
  • ChartWrapper constructor options claiming that you must load third-party libraries but not google.visualization libraries here
I'm having problems loading a 'Map' chart type. When trying to load a map I receive the error 'object is not iterable (cannot read property Symbol(Symbol.iterator))' If I don't explicitly load the 'map' package. Here's an example piece of code that can be run to reproduce the issue.

<html>
  <head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
      google.charts.load('current');
      // google.charts.load('current', { packages: ['map']});
      google.charts.setOnLoadCallback(drawMap);

      function drawMap() {
        let mapWrapper = new google.visualization.ChartWrapper({
            chartType: 'Map',
            dataTable: [
              ['lattitude', 'longitude', 'label'],
              [-37.7647, 144.9393, 'hello'],
              [40.4165, -3.7026, 'hello2']
            ],
            options: {'title': 'Stuff'},
            container: document.getElementById('map_div')
        });

        mapWrapper.draw();
      }
    </script>
  </head>
  <body style="font-family: Arial;border: 0 none;">
    <div id="map_div" style="width: 600px; height: 400px;"></div>
  </body>
</html>

If you run as-is, you will receive the error. If you uncomment the load call with the 'map' package then everything loads just fine. Is the Google Maps library considered a third-party library or is this a bug or am I missing something? Any help here would be greatly appriciated. Thank you!

Almania M

unread,
Apr 15, 2021, 1:51:45 AM4/15/21
to Google Visualization API
Looks like it might be a bug in the ChartWrapper? I did some debugging and found a possible issue where ChartWrapper (I think) checks for the chart type by looking at possible namespaces. The issue is that when there aren't any loaded packages that contain a 'Map' constructor function it lands on just 'Map'. The check always start from the Window object so when all other namespaces fail it succeeds on Window.Map, which is just a JavaScript Map data structure. I tested removing the last part of the array (the 'Map' value) and it successfully loaded the Google Maps api.
google-chart-wrapper-debug.png
Reply all
Reply to author
Forward
0 new messages