-1

我使用 d3.js 和 CodeIgniter,当我在运行此代码时使用 d3.json 获取 json 数据时遇到问题:

var url = "http://probe.dev/draw/windRose?station=vp2&sensors=wind&Since=2012-10-15T00:00:00&StepUnit=DAY&StepNbr=6;
d3.json(url, function(d) {
    console.log(d); // print NULL in console
}

但它适用于

$.getJSON(url, function(d) {
    console.log(d); // print my data object correctly
}

我的 php 代码是:

<?php
@ob_end_clean();
 header('Content-Type: "application/json"');
 header('Content-Disposition: attachment; filename="data.json"');
 header("Content-Transfer-Encoding: binary");
 header('Expires: 0');
 header('Pragma: no-cache');
 header("Content-Length: ".strlen($data));
  exit($data);

我不明白为什么 d3.json 不起作用?

4

1 回答 1

5

我无法让它与 v2 一起工作,我搬到了d3js.v3并且它工作了。

v3 中的回调函数有两个参数:

d3.json(url, function(error, json) {
    if (error) return console.warn(error);
    else ...;
}
于 2013-01-12T18:44:11.200 回答