flot display the date in flot based on timestamp

后端 未结 4 1063
清歌不尽
清歌不尽 2020-12-09 20:54

Does anyone know how to display the date in flot based on timestamp



        
相关标签:
4条回答
  • 2020-12-09 21:08

    I use this:

        var options = {
        lines: { show: true },
        points: { show: true },
        xaxis: { mode: "time",  timeformat: "%m/%d/%y",   minTickSize: [1, "day"]}
    };
    
    0 讨论(0)
  • 2020-12-09 21:13

    I guess all you need to do is to multiply the timestamp (which look like unix timestamps) by 1000.

    Unix timestamp tracks time as a running total of seconds starting from January 1st, 1970. While javascript timestamps measure milliseconds. So just multiply by 1000 and you should be fine

    0 讨论(0)
  • 2020-12-09 21:17

    Try defining the 'timeformat' attribute, and define the pattern that flot will use to format the millisecond value.

    xaxis:{
        mode: "time",
        timeformat: "%M:%S"
    },
    
    0 讨论(0)
  • 2020-12-09 21:19

    I just ran into this and I think we both used the same bad Flot example. The signature is:

    var plot = $.plot(placeholder, data, options)
    

    And your code is doing something like

    var plot = $.plot(placeholder, data, xoptions, yoptions)
    

    So to fix it, just do this instead:

    $.plot(
        $("#placeholder"), 
        [{data:d1,lines:{show: true},label:"Mountain"},{data:d2,lines:{show:true},label:"Valley"}],
        {yaxis: {label:"cm"}, xaxis: {mode:"time"}}
    );
    
    0 讨论(0)
提交回复
热议问题