Display Timeline/Linear data in Flot

泄露秘密 提交于 2020-01-06 07:15:36

问题


Does anyone know how to get flot to display a type of 'timeline'?

E.g.

Y:
Person1| -----     -------
Person2|    -------   -------
Person3| -- -----    ----
Person4|       -------
        _____________________
X:      Jan  Feb  March  April

I'm not sure how to display the labels on the y axis and show the data linear

Solution so far :)

$(document).ready(function(){

var d1 = [[(new Date("01/01/2009")).getTime(), 5], [(new Date("10/01/2009")).getTime(), 5]];

var placeholder = $("#placeholder");

// plot it
var plot = $.plot(placeholder, [d1], {xaxis:{mode:"time", timeformat:"%b.%y"}});

});

Thanks in advance!


回答1:


Finally found the answer. Use the configuration 'ticks'.

Solution:

//american dates
    var d1 = [[(new Date("01/01/2009")).getTime(), 1], [(new Date("01/10/2009")).getTime(), 1]];
    var d2 = [[(new Date("05/05/2009")).getTime(), 2], [(new Date("06/23/2009")).getTime(), 2]];
    var d3 = [[(new Date("03/10/2009")).getTime(), 3], [(new Date("03/15/2009")).getTime(), 3]];
    //var d1 = [[0, 5], [5, 5], null, [5, 10], [15, 10]];
    var placeholder = $("#placeholder");

    // plot it
    var plot = $.plot(placeholder, [d1,d2,d3], {
        xaxis:{mode:"time", timeformat:"%b.%y"},
        yaxis:{ticks:[[1, "Apple"], [2, "Microsoft"], [3, "Dell"]]}
    });



回答2:


View the source of http://people.iola.dk/olau/flot/examples/basic.html pay particular attention to the comment // a null signifies separate line segments I think that should get you where you want to be.



来源:https://stackoverflow.com/questions/10987870/display-timeline-linear-data-in-flot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!