4

我试图在我的图表中显示月/年,但是 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);
    }
4

3 回答 3

1

在 xaxis 选项下,设置:

minTickSize = [1, "month"]

现在发生的情况是,Flot 自然会尝试每月多次生成刻度,然后由于您的格式字符串而显示为同一月份。

于 2012-06-29T12:06:30.710 回答
0
var options = {
    lines: { show: true },
    points: { show: true },
    xaxis: { mode: "time", 
    timeformat: "%m/%y",   
    minTickSize: [1, "day"], 
    tickSize: [1, "month"]}
    };
于 2012-07-09T23:29:59.513 回答
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 }
    };
于 2012-09-19T14:37:50.237 回答