1
我一直在试图创造出每天统计一个dc.js rowchart,我维和组是d3.time/crossfilter天是关闭一个
var dayNameFormat = d3.time.format("%A");
var weekDayFormat = d3.time.format('%w'); //weekday as a decimal number [0(Sunday),6].
var dayOfWeek = ndx.dimension(function(d) {
return weekDayFormat(d.date) + '.' + dayNameFormat(d.date);
});
var dayOfWeekGroup = dayOfWeek.group().reduce(
function(p, d) {
++p.count;
p.totalPoints += +d.points_per_date;
p.averagePoints = (p.totalPoints/p.count);
if (d.student_name in p.studentNames) {
p.studentNames[d.student_name] += 1
} else {
p.studentNames[d.student_name] = 1;
p.studentCount++;
}
return p;
},
function(p, d) {
--p.count;
p.totalPoints -= +d.points_per_date;
p.averagePoints = (p.totalPoints/p.count);
if (p.studentNames[d.student_name] === 0) {
delete p.studentNames[d.student_name];
p.studentCount--;
}
return p;
},
function() {
return {
count: 0,
totalPoints: 0,
averagePoints: 0,
studentNames: {},
studentCount: 0
};
});
和图表
dayOfWeekChart
.width(250)
.height(180)
.margins({
top: 20,
left: 20,
right: 10,
bottom: 20
})
.dimension(dayOfWeek)
.group(dayOfWeekGroup)
.valueAccessor(function(d) {
return d.value.totalPoints
})
.renderLabel(true)
.label(function(d) {
return d.key.split('.')[1] + '(' + d.value.totalPoints + ' points)';
})
.renderTitle(true)
.title(function(d) {
return d.key.split('.')[1];
})
.elasticX(true);
我希望的结果,以配合我的那些数据库查询
的到TAL值是正确的,但是天已经由天偏移(星期日有周一的总)
我的小提琴https://jsfiddle.net/santoshsewlal/txrLw9Lc/ 我一直在做我的头,试图得到这个权利,任何帮助将很棒。 感谢
谢谢@Gordon。使用d3.time.format.utc(“%Y-%m-%dT%H:%M:%S.%LZ”)做到了这一点。我发现在这里,http://stackoverflow.com/questions/33755972/d3-datetime-parser-takes-into-account-timezone –
啊,是我忘了说了'.utc'变种,这是一个很好的点。 – Gordon