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