我正试图用DC,D3和交叉滤波器制作一个网页,但是开发人员工具提醒我以下错误。
未被捕获的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>
最佳答案
我认为您应该这样处理您的问题:
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 */
});
<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>
对于var ndx = crossfilter(data);
,数据未定义(仅在csv
第一个回调内部定义)。就像文档(learnjsdata.com/read_data.html)中出现的一样,csv
第一个回调有一个参数,而不是两个...关于javascript - d3和crossfilter js错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50451728/
10-12 07:10