简体   繁体   English

绘制奇怪的折线图

[英]Flot Strange Line Chart

I have a chart with ordering by date. 我有一张按日期排序的图表。

My problem is the chart lines joining false from start to end. 我的问题是图表行从头到尾加入false。

在此输入图像描述

My options: 我的选择:

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

Note: I'm not re-ordering any data. 注意:我没有重新订购任何数据。 Just giving the timestamp with this function: 只是给这个函数的时间戳:

function gd(year, month, day) {
    return new Date(year, month - 1, day).getTime();
}

Setting the data like this: 像这样设置数据:

$.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);

Console log: 控制台日志:

在此输入图像描述

When creating line charts, flot will connect the data points using the order from the data series, ignoring the actual x-coordinates. 创建折线图时,flot将使用数据系列中的顺序连接数据点,忽略实际的x坐标。 That's why data series should be in ascending order. 这就是为什么数据系列应该按升序排列的原因。

A minimal example (using your data in ascending order): 一个最小的例子(按升序使用您的数据):

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

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

Here is a jsfiddle showing the chart. 这是一个显示图表的jsfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM