我通过 here 检查周数。我检查了第 29 周是从 2015 年 7 月 12 日到 2015 年 7 月 18 日。但是在莫里斯图表中,w29 是 2015 年 7 月 19 日到 25 日。我在哪里可以快速更正这个问题?
//js
var line = new Morris.Line({
element: 'line-chart',
resize: true,
data: result_week,
xkey: 'week',
ykeys: ['price'],
labels: ['Price'],
xLabels: ['week'],
lineColors: ['#3c8dbc'],
hideHover: 'auto',
smooth: false
});
此外,有什么方法可以将 x 轴标签显示为“2015-W29”而不是日期格式?
请指教。谢谢。
更新: 我将 morris.js 更改为减去周 -1,我知道减去 1 是不对的。但仍然希望有更好的解决方案。问题仍然悬而未决!谢谢。
"week": {
span: 604800000,
start: function(d) {
return new Date(d.getFullYear(), d.getMonth(), d.getDate());
},
fmt: function(d) {
// return "" + (d.getFullYear()) + "-" + (Morris.pad2(d.getMonth() + 1)) + "-" + (Morris.pad2(d.getDate()));
Date.prototype.getWeek = function() {
var onejan = new Date(this.getFullYear(), 0, 1);
return Math.ceil((((this - onejan) / 86400000) + onejan.getDay() + 1) / 7);
}
return "" + (d.getFullYear()) + " W" + (Morris.pad2(d.getWeek() - 1));
},
incr: function(d) {
return d.setDate(d.getDate() + 7);
}
},
最佳答案
一种方法是provide your own hoverCallback()
function :
Provide a function on this option to generate custom hover legends. The function will be called with the index of the row under the hover legend, the options object passed to the constructor as arguments, a string containing the default generated hover legend content HTML, and an object containing the original data for the row as passed in the data option.
在该功能中,您可以调整显示的周数(完全覆盖内容
或仅修改周数)。
关于javascript - Morris.js 中的周数不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31914057/