You should read the documentation at https://developers.google.com/chart/interactive/docs/datatables_dataviews Note that the way you use JSON makes a difference. What you are doing would make sense, but it is not supported.
You should probably just use the simpler array of arrays form, so generate JSON like this instead: [[6, 4], [6, 5}, ...] On Wed, Oct 25, 2017 at 5:29 AM, rocky <[email protected]> wrote: > I get JSON like; > > [{"ph":6,"broj":4},{"ph":6,"broj":5},{"ph":7,"broj":6},{"ph":9,"broj":8},{"ph":5,"broj":9}] > > > And now I have troble in HTML row: > > google.charts.setOnLoadCallback(drawChart); //row 13 > data.addRows(JSON.parse(jsonData)); //row 28 > > > > > ERROR is: > > Uncaught (in promise) SyntaxError: Unexpected token u in JSON at position 0 > at JSON.parse (<anonymous>) > at drawChart (load.html:28) > at <anonymous> > drawChart @ load.html:28 > Promise resolved (async)google.G.H.T.nl @ loader.js:225 > (anonymous) @ load.html:13 > > > *Do you have any idea?* > > > HTML code > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > > <html> > <head> > <!--Load the AJAX API--> > <title>Pregled mjerenih podataka</title> > <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> > <script type="text/javascript" > src="https://www.gstatic.com/charts/loader.js"></script> > <script type="text/javascript" > src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> > <script type="text/javascript"> > > google.charts.load('current', {packages: ['corechart', 'line']}); > google.charts.setOnLoadCallback(drawChart); > > function drawChart() { > var jsonData = $.ajax({ > url: "getData2.php", > dataType: "json" > }).responseText; > > // Create our data table out of JSON data loaded from server. > var data = new google.visualization.DataTable(); > data.addColumn('number', 'ph'); > data.addColumn('number', 'broj'); > > //var foo = '[[2004, 5],[2005, 8.5],[2006,6.5],[2007,8]]'; > > data.addRows(JSON.parse(jsonData)); > //data.addRows(JSON.parse(jsonData)); > > var options = { > title:'pH vrijednosti zadnjih 5 mjerenja', > > width: 1000, height: 300, > > hAxis: { > title:'datum' > }, > vAxis: { > title: 'pH' > }, > }; > > > var chart = new > google.visualization.LineChart(document.getElementById('chart_div')); > chart.draw(data, options); > } > </script> > </head> > > <body> > <!--Div that will hold the pie chart--> > <div id="text">Graf</div> > <div id="chart_div"></div> > </body> > </html> > > > -- > 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 google-visualization-api@ > googlegroups.com. > 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/d9d7f4b2-38c3-4424-aa70- > 3afdc87de577%40googlegroups.com > <https://groups.google.com/d/msgid/google-visualization-api/d9d7f4b2-38c3-4424-aa70-3afdc87de577%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- Daniel LaLiberte <https://plus.google.com/100631381223468223275?prsrc=2> [email protected] <[email protected]> 5CC, Cambridge MA -- 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/CAOtcSJMj60YDqQ3F68KJ9LB1-sdGVPQys3wjp-SnUEX1EP_ugg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
