Javascript 弗洛特奇异线图

Javascript 弗洛特奇异线图,javascript,flot,Javascript,Flot,我有一张按日期排序的图表 我的问题是图表线从头到尾都是假的 我的选择: var options = { grid: { color: "#dedede", borderWidth: 1, borderColor: "transparent", clickable: true, hoverable: true },

我有一张按日期排序的图表

我的问题是图表线从头到尾都是假的

我的选择:

var options =
    {
        grid:
        {
            color: "#dedede",
            borderWidth: 1,
            borderColor: "transparent",
            clickable: true,
            hoverable: true
        },
        series: {
            grow: {active:false},
            lines: {
                show: true,
                fill: false,
                lineWidth: 2,
                steps: false
            },
            points: {
                show:true,
                radius: 5,
                lineWidth: 3,
                fill: true,
                fillColor: "#000"
            }
        },
        legend: { position: "nw", backgroundColor: null, backgroundOpacity: 0, noColumns: 2 },
        yaxis: { tickSize:50 },
        xaxis: {
            mode: "time",
            tickFormatter: function(val, axis) {
                var d = new Date(val);
                return d.getUTCDate() + "/" + (d.getUTCMonth() + 1);
            }
        },
        colors: [],
        shadowSize:1,
        tooltip: true,
        tooltipOpts: {
            content: "%s : %y.0",
            shifts: {
                x: -30,
                y: -50
            },
            defaultTheme: false
        }
    };
注意:我没有重新订购任何数据。只需使用此函数提供时间戳:

function gd(year, month, day) {
    return new Date(year, month - 1, day).getTime();
}
如下所示设置数据:

$.each(e.data, function(i, e){
    data.push([gd(parseInt(e['year']), parseInt(e['month']), parseInt(e['day'])), parseInt(e['value'])]);
});

var entity = {
    label: e.campaign,
    data:  data,
    lines: {fillColor: randomColor},
    points: {fillColor: randomColor}
};

entities.push(entity);
控制台日志:


创建折线图时,flot将使用数据系列中的顺序连接数据点,忽略实际的x坐标。这就是为什么数据系列应该按升序排列

一个简单的示例(按升序使用数据):


显示图表。

看起来排序数据的算法是错误的(先按天排序,然后按月排序)。@Juhana I'v更新了我的问题。AFAIK flot将使用数据系列中的顺序连接数据点,而忽略实际的x坐标。对数据进行排序应该可以解决这个问题。这就是你要找的吗?是的,没错。我将尝试重新排序数据thank you.data.sort(函数(x,y){return x[0]-y[0];});-排序:)作为注释:这是Flot的一个特性;使它成为一个绘图库,而不仅仅是一个图表库。许多其他库都无法做到这一点。
var d1 = [
    [1401310800000, 275],
    [1401397200000, 270],
    [1401483600000, 313],
    [1401570000000, 279], 
    [1401656400000, 216], 
    [1401742800000, 255], 
    [1401829200000, 244],
    [1401915600000, 70]                     
];

$.plot("#chart", [ d1 ]);