score:1

Accepted answer

d3.json() expects a url as its first parameter, not a json string. this will in turn request the specified file at that particular url to load the json from.

in your case, however, it might be easier to directly assign the json to the data variable.

var data = json.parse("<?php echo json_encode($viewmodel) ?>");

data.foreach(function(d) {
  //...
});

Related Query