JSON error when calling chart.draw from Google GeoChart library

33 views
Skip to first unread message

Gonzalo Rodríguez Píriz

unread,
Sep 30, 2015, 3:14:28 AM9/30/15
to Google Visualization API
Hi all!

I'm trying to use Google GeoChart library to display a map, and if I do it on a local HTML file or somewhere like JSFiddle, it works perfectly. 

However, when I embed it in a JSP on my project and deploy it (using JBoss), calling `chart.draw` results in a JSON error:

    Invalid JSON string: {":",":",":{":[",","]},":",":{":true}}

My complete Javascript method is as follows:

var data2 = google.visualization.arrayToDataTable([
                                                  [{label: 'Country', type: 'string'},
                                                   {label: 'description', type: 'string'},
                                                   {label: 'consistency', type: 'number'},
                                                   {type: 'string', role: 'tooltip'}],
                                                   ['Canada', "CANADA", 2, "OK"],
                                                   ['France', "FRANCE", 0, "KO"],
                                                   ['USA', "USA", 1, "Other"]
                                                ]);

    var options = {
            displayMode: 'region',
            backgroundColor: '#81d4fa',
            colorAxis: {
                colors: ['red', 'orange', 'green']
            },
            legend: 'none',
            tooltip: {
                showColorCode: true
            }
        };

     var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
     chart.draw(data2, options);    

So it's clearly picking up the "structure" of the JSON object (two simple objects, another object with an array inside, another simple object, another object with an array inside), but for some reason is not picking up the content, except for the 'true' value, so it looks like a problem with quotes... 

In any case, I have tried simple and double quotes, removing the quotes from the identifiers, reducing the `options` object to a simple

    var options = {
"legend": "none"
};

... but to no avail. Everything results in a `Invalid JSON string` error (in this last case, a `Invalid JSON string: {":"}` error, since there is only one object).

Last note: if I just use

    var options = {};

it shows the map (but with the default options).

Any ideas as to why is this happening and/or how to solve it?

Thanks!
message.PNG

Daniel LaLiberte

unread,
Sep 30, 2015, 8:12:15 AM9/30/15
to Google Visualization API
Gonzalo,

It would be useful to look at the html that is generated from the JSP.  Do "view source" in your browser.  Perhaps by looking at that you will be able to figure out how you need to change your JSP.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/8db49e7a-bb69-4f5a-b0a7-9db38b6188ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
dlaliberte@Google.com   5CC, Cambridge MA
daniel.laliberte@GMail.com 9 Juniper Ridge Road, Acton MA

Gonzalo Rodríguez Píriz

unread,
Oct 2, 2015, 3:52:59 AM10/2/15
to Google Visualization API
Thank you, Daniel.

The HTML seemed to be generated successfully, and the options object arrived at the chart.draw method with all the values.

Anyway, I created a new JSP, added everything as it was and it worked... so I started working on that new one. Guess I'll never know what happened, but hey, it's working now :)

Thanks!

Gonzalo.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA
Reply all
Reply to author
Forward
0 new messages