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

More Query from same tag