我想制作一个包含DC,D3和crossfilter的网页,但开发人员工具会让我想起以下错误。
未捕获的ReferenceError:未定义数据
d3.csv("mydata.csv", function(error, data) {
if (error) throw error;
console.log(data);
});
var ndx = crossfilter(data);
var ratingDim = ndx.dimension(function(d) { return d.rating; });
var total_10 = ratingDim.filter(3);
function print_filter(filter){
var f=eval(filter);
if (typeof(f.length) != "undefined") {}else{}
if (typeof(f.top) != "undefined") {f=f.top(Infinity);}else{}
if (typeof(f.dimension) != "undefined") {f=f.dimension(function(d) { return "";}).top(Infinity);}else{}
console.log(filter+"("+f.length+") = "+JSON.stringify(f).replace("[","[\n\t").replace(/}\,/g,"},\n\t").replace("]","\n]"));
}
print_filter("total_10");
<script src="https://cdnjs.cloudflare.com/ajax/libs/dc/3.0.3/dc.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crossfilter/1.3.12/crossfilter.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
答案 0 :(得分:2)
我认为你应该以这种方式处理你的问题:
var data_url = "https://gist.githubusercontent.com/tikeda123/5e7cf7f40ea96a273273729cb6320e12/raw/198db29f442ef3a96b72fb57d72c56eaa8862c09/log.csv"
d3.csv(data_url,
function(data) {
var ndx = crossfilter(data);
/* Continue with your code here */
});
&#13;
<script src="https://cdnjs.cloudflare.com/ajax/libs/dc/3.0.3/dc.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crossfilter/1.3.12/crossfilter.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
&#13;
未定义var ndx = crossfilter(data);
数据(仅在csv
第一次回调中定义)。另外,因为它出现在文档(learnjsdata.com/read_data.html)csv
中,第一个回调有一个参数,而不是两个......