Invalid row type for row 0

1,732 views
Skip to first unread message

Stelios Voskos

unread,
Jan 24, 2014, 10:31:53 AM1/24/14
to google-visua...@googlegroups.com

I have to visualize some url json data on a pie chart with google visualization. My code seems to be as it has to be for the purpose, but I am getting an 'Invalid row type for row 0' error in the console. Is there any problem with the format of the data? If there is anyone that could help, that would be much appreciated. Here is my code:

PHP:

<?php
    $json = file_get_contents('http://data.police.uk/api/crimes-street/all-crime?lat=52.629729&lng=-1.131592&date=2013-01'); 
    $json = str_replace("\xe2\x80\xa8", '\\u2028', $json);
    $json = str_replace("\xe2\x80\xa9", '\\u2029', $json);
    echo $json;
?>

JavaScript:

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">

// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['corechart']});

// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);

function drawChart() {
  var jsonData = $.ajax({
      url: "getData.php",
      dataType:"json",
      async: false
      }).responseText;

  //Create an array of the JSON data and then create our data table out of JSON data loaded from server.
  var array = JSON.parse(jsonData);
  var dataTableData = new google.visualization.arrayToDataTable(array);
  var table = google.visualization.DataTable(dataTableData);

  var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
  chart.draw(data, {width: 400, height: 240});
}

</script>
</head>

<body>
<div id="chart_div"></div>
</body>

Thank you.

asgallant

unread,
Jan 24, 2014, 11:06:57 AM1/24/14
to google-visua...@googlegroups.com
The JSON string returned by http://data.police.uk/api/crimes-street/all-crime?lat=52.629729&lng=-1.131592&date=2013-01 is not in the correct format for the Google Visualization API.  Also, the json contains many categories of data, while the PieCharts expect to see two columns of data: one "string" type for pie slice labels and one "number" type for pie slice values.  What data do you want to chart?

Stelios Voskos

unread,
Jan 24, 2014, 11:26:53 AM1/24/14
to google-visua...@googlegroups.com
Thank you for replying. Well,if I can visualize just 2 categories, then I would say the category of the crime and the location. How can I do that though? Thanks again

asgallant

unread,
Jan 24, 2014, 12:21:45 PM1/24/14
to google-visua...@googlegroups.com
One of the columns of data must be numeric for the PieChart to work.  As an example, you could create a PieChart that charts a count of each category.  You can create multiple PieCharts as well, if you want to chart more than one set of data.

Stelios Voskos

unread,
Jan 27, 2014, 4:46:24 AM1/27/14
to google-visua...@googlegroups.com
Hi mate. Just saw your reply and I've got it semi-working. Thanks for your help! :)

Stelios Voskos

unread,
Jan 27, 2014, 4:47:04 AM1/27/14
to google-visua...@googlegroups.com
Hi mate. Just saw your reply and I've got it semi-working. Thanks for your help! :)

Reply all
Reply to author
Forward
0 new messages