Gents I have a similarly weird JSON string error coming from the Google visualisation API. However, mine isn't coming from the data I'm pulling from a service it's coming from the static options JSON string I have in my code snippet.
Here is a JS Fiddle of the example working: https://jsfiddle.net/8ynmrotc/1/ However, when I add this example to my Rails application I get a message saying invalid JSON string and with the contents of the options variable. The charts library is added to my vendor js libs and there's no backend code being called at all. The only thing I can think that might be causing it is potentially some interaction with my jquery/jquery-ui but I see no errors and didn't think the charts/visualisation js used separate libs for calls to the gstatic API... Any ideas what's causing this I'm totally out of ideas? *JS:* $(document).ready(function() { google.charts.load('current', {'packages':['corechart']}); google.charts.setOnLoadCallback(drawChart); function calculatePosition(y, a, t, v) { return y + v*t + ((a*t)^2)/2; } function drawChart() { var y = 0; var v = 1; var a = 2; var data = new Array(); data[0] = new Array('Time', 'Growth'); for (var t = 1; t <= 10; t++) { y = calculatePosition(y, a, t, v); v = a*t; data[t] = new Array(t, y); } var data = google.visualization.arrayToDataTable(data); // options JSON "causing" issues var options = { title: 'Accelerated Growth', curveType: 'function', legend: { position: 'bottom' } }; var chart = new google.visualization.LineChart(document.getElementById( 'curve_chart')); chart.draw(data, options); } }); *show.html.erb* <div id="proactive-metrics-container"> <h1><%= @partner.name %></h1> <div id="curve_chart" style="width: 900px; height: 500px"></div> </div> The source lib I downloaded and added to vendor pipeline: https://www.gstatic.com/charts/loader.js On Friday, 8 May 2015 09:07:16 UTC+1, Manuel wrote: > > Hi all, > > I just encountered a weird problem.I get the following error: > > Uncaught Error: Invalid JSON string: > > > <!DOCTYPE html> > > > > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de-de" > > AND A LOT MORE THEREAFTER > > when I use this code: > > <html> > <head> > > <script type="text/javascript" src="https://www.google.com/jsapi > "></script> > <script src="varChart.js" type="text/javascript"></script> > <script type="text/javascript"> > google.load('visualization', '1', {packages: ['corechart', 'bar']}); > google.setOnLoadCallback(drawBasic); > > function drawBasic() { > > var jsonData = jQuery.ajax({ > url: "charting/Country.php?country=2&Type=0", > dataType:"json", > async: false > }).responseText > var data = new google.visualization.DataTable(jsonData); > > var options = { > }; > > var chart = new google.visualization.ColumnChart( > document.getElementById('chart_div')); > > chart.draw(data, options); > } > </script> > > </head> > <body> > > <div id="chart_div" style="height: 300px;margin-top:10px"></div> > <p style="font-size: x-small;color: grey;text-align: right;">Quelle: > eigene Berechnung, OECD Housing Prices database; OECD Economic Outlook > database</p> > > > </body> > </html> > > But when I vaildate my JSON everything is just fine! > > Can anybody help me on this? Do you need mor information? > > Thank you very much > > Best > Manu > > > -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/google-visualization-api. To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/ef663f68-f845-4eef-a141-a605ddf8957f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
