我是JS的新手。我知道之前已经问过这个问题 - 找到独特的用户。我无法工作的是从服务器获取数据的情况。每当我尝试从服务器导入数据时,我都会出现一个空白屏幕。这是.js文件:
// Objective-C
UIApplication *application = [UIApplication sharedApplication];
[application openURL:URL options:@{} completionHandler:nil];
// Swift
UIApplication.shared.open(url, options: [:], completionHandler: nil)
目前我正在关注此答案 - Crossfilter : find unique values
这是位于queue()
.defer(d3.json, "/data2")
.await(makeCharts);
function makeCharts(error, recordsJson) {
//Clean data
var records = recordsJson;
var dateForm = d3.time.format("%Y-%m-%d %H:%M:%S");
records.forEach(function(d) {
d["timestamp"] = dateForm.parse(d["timestamp"]);
d["timestamp"].setHours(0,0,0);
});
var ndx = crossfilter(records);
var dateDim = ndx.dimension(function(d) { return d["timestamp"]; });
var num_unique_ids_by_date = dateDim.group()
.reduce(
function (p, d) {
if(d.userid in p.userids) p.userids[d.userid] ++;
else{
p.userids[d.userid] = 1;
p.id_count++;
}
return p;
},
function (p, d) {
p.userids[d.userid]--;
if(p.userids[d.userid] === 0){
delete p.userids[d.userid];
p.id_count--;
}
return p;
},
function () {
return {userids: {},
id_count: 0};
});
var timeXChart = dc.rowChart("#time-chartX");
timeXChart
.width(650)
.height(140)
.dimension(dateDim)
.group(num_unique_ids_by_date)
.valueAccessor(function(d){
return d.value.id_count;
})
.elasticX(true) ;
dc.renderAll();
};
的JSON格式的示例数据:
localhost:8080/data2
这是错误日志 -
[{"userid":81,"timestamp":"2016-07-29 07:01:37"},
{"userid":191,"timestamp":"2016-07-31 07:56:05"},
{"userid":36,"timestamp":"2016-08-01 01:44:41"},
{"userid":104,"timestamp":"2016-07-28 05:45:51"},
{"userid":184,"timestamp":"2016-08-02 06:22:10"},
{"userid":82,"timestamp":"2016-07-28 05:05:10"},
{"userid":220,"timestamp":"2016-08-05 06:39:19"},
{"userid":16,"timestamp":"2016-06-04 03:44:40"},
{"userid":16,"timestamp":"2016-06-04 03:48:29"},
{"userid":16,"timestamp":"2016-06-04 03:48:54"},
{"userid":16,"timestamp":"2016-06-04 03:50:09"},
{"userid":16,"timestamp":"2016-06-04 06:14:34"}];