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 [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/d9d7f4b2-38c3-4424-aa70-3afdc87de577%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.