浮选奇怪的折线图 [英] Flot Strange Line Chart

查看:88
本文介绍了浮选奇怪的折线图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按日期排序的图表.

I have a chart with ordering by date.

我的问题是图表线从头到尾连接在一起.

My problem is the chart lines joining false from start to end.

我的选择:

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

像这样设置数据:

$.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坐标.这就是为什么数据序列应该按升序排列.

When creating line charts, flot will connect the data points using the order from the data series, ignoring the actual x-coordinates. 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 ]);

这是显示图表的jsfiddle .

这篇关于浮选奇怪的折线图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆