Reputation: 177
Following on from this thread: Accessing MySQL database - D3
Can anyone help with a parse error I'm getting? There seems to be conflicting information out there about what can cause this?
Parse error:
Error: Problem parsing d="M30,NaNL34,NaNL38,NaNL42,NaNL46,NaNL50,NaNL54,NaNL58.......
getdata.php:
<?php
$username="*****";
$password="*****";
$host="********";
$link=mysql_connect($host,$username,$password)
or die("Unable to connect to MySQL");
mysql_select_db("*****", $link) or die( "Unable to select database"
.mysql_error());
$res = mysql_query("SELECT * FROM TestSourceSampleData")
or die ("Unable to run query");
$data = array();
while ($row = mysql_fetch_assoc($res))
{
$data[] = array("reading" => $row['reading']);
}
echo json_encode($data);
mysql_close($link);
?>
Output from getdata.php:
[{"reading":"10"},{"reading":"10.2"},{"reading":"10.3"},{"reading":"10.3"}........
..when print json file:
Array[120]
[0 … 99]
0: Object
reading: "10"
__proto__: Object
1: Object
reading: "10.2"
__proto__: Object
2: Object
reading: "10.3"
__proto__: Object
3: Object
4: Object
5: Object
http://bl.ocks.org/5fc4cd5f41a6ddf2df23
Upvotes: 0
Views: 503
Reputation: 5233
In your block you use:
var data = jsondata.map(function(d) { return d.Value; });
while in your question you mention that the name of the key is reading
, which would mean your code should look like:
var data = jsondata.map(function(d) { return d.reading; });
Upvotes: 1