我正在尝试在图表中显示月份/年份,但x轴上有标签错误:
2012年4月3次(以及5月和6月)。
这是代码
function showGraph() {
var data = [
{ label : "Odmeny", data: [ [(new Date('2012/04/01')).getTime(), 10], [(new Date('2012/05/01')).getTime(), 10], [(new Date('2012/06/01')).getTime(), 10] ] },
{ label : "Koeficienty", data: [ [(new Date('2012/04/01')).getTime(), 11], [(new Date('2012/05/01')).getTime(), 13], [(new Date('2012/06/01')).getTime(), 16], [(new Date('2012/07/01')).getTime(), 12] ] }
];
var options = {
xaxes: [{
mode: "time",
timeformat: "%b %y",
monthNames: ["jan", "feb", "mar", "apr", "máj", "jún", "júl", "aug", "sep", "okt", "nov", "dec"]
}],
yaxes: [ {
min: 0
} ],
series: {
lines: {
show: true,
fill: null
},
points: {
show: true,
radius: 3,
lineWidth: 2,
fill: true,
fillColor: "#ffffff",
symbol: "circle"
}
},
grid: { hoverable: true, clickable: true }
};
$.plot($("#placeholder"), data, options);
}
答案 0 :(得分:1)
在xaxis选项下,设置:
minTickSize = [1, "month"]
现在发生的事情是,Flot自然会尝试每月生成一次以上的刻度,然后由于您的格式字符串而出现在同一个月。
答案 1 :(得分:0)
var options = {
lines: { show: true },
points: { show: true },
xaxis: { mode: "time",
timeformat: "%m/%y",
minTickSize: [1, "day"],
tickSize: [1, "month"]}
};
答案 2 :(得分:0)
工作代码(无minThickSize):
var options = {
xaxes: [{
mode: "time",
timeformat: "%b %y",
monthNames: ["jan", "feb", "mar", "apr", "máj", "jún", "júl", "aug", "sep", "okt", "nov", "dec"]
}],
yaxes: [ {
min: 0
} ],
series: {
lines: {
show: true,
fill: null
},
points: {
show: true,
radius: 3,
lineWidth: 2,
fill: true,
fillColor: "#ffffff",
symbol: "circle"
}
},
grid: { hoverable: true, clickable: true }
};