簡體   English   中英

繪制奇怪的折線圖

[英]Flot Strange Line Chart

我有一張按日期排序的圖表。

我的問題是圖表行從頭到尾加入false。

在此輸入圖像描述

我的選擇:

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坐標。 這就是為什么數據系列應該按升序排列的原因。

一個最小的例子(按升序使用您的數據):

var d1 = [
    [1401310800000, 275],
    [1401397200000, 270],
    [1401483600000, 313],
    [1401570000000, 279], 
    [1401656400000, 216], 
    [1401742800000, 255], 
    [1401829200000, 244],
    [1401915600000, 70]                     
];

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

這是一個顯示圖表的jsfiddle

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM