jQuery 浮点 : reapeating labels on x-axis

标签 jquery flot

我尝试在图表中显示月份/年份,但 x 轴上的标签存在错误:

enter image description here

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);
    }

最佳答案

在 xaxis 选项下,设置:

minTickSize = [1, "month"]

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

关于jQuery 浮点 : reapeating labels on x-axis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11250027/

相关文章:

javascript - jQueryUI 拖动的项目为第一个可放置后面的每个元素触发放置

javascript - 如何根据文本长度立即显示和隐藏字段? - jQuery

jquery - MVC 部分 View 使用 jquery.get() 触发 Document.Ready(),但不触发 Ajax.BeginForm

jquery - 将鼠标悬停在图上并更改图标题?

jquery - 我怎样才能改变图例 jquery flot 的形状

javascript - 如果flot中只有一个数据点,如何显示日期标签?

javascript - 如何在不延迟的情况下正确获取 setInterval 内的某些元素宽度?

javascript - Flotplothover - pos.y 未定义

javascript - 相邻 HTML div 中的两个 float 图表导致问题

javascript - 在图表中显示来自 mysql 的日期