在Graph2d中,有时点没有连接

时间:2017-06-22 10:11:24

标签: javascript vis.js

我正在使用vis.js v.4.12.0。我注意到有时使用Graph2d有些点没有连接。









我认为这种行为取决于点距离;有人知道如何强制点连接吗?




1 个答案:

答案 0 :(得分:0)

@ selten98:当然,这是我的代码:

for (var i in plot) {
    groups.add({
        content: labelArray[i],
        id: plot[i],
        options: {
            shaded: {
                orientation: "bottom"
            }
        }
    });

    for (var j in GD) {
        if (GD[j].hasOwnProperty(plot[i])) {
            items.push({
                group: plot[i],
                label: {
                    className: "visibility-hidden label-group-" + labelArray[i],
                    content: GD[j][plot[i]].toFixed(1),
                    xOffset: -10 / 3 * GD[j][plot[i]].toFixed(1).length,
                    yOffset: 20
                },
                x: new Date(GD[j].timestamp),
                y: Number(String(GD[j][plot[i]]).replace(",", "."))
            });
        }
    }
}

for (var i = 0; i < items.length; i++) {
    if (i == 0) {
        groups.add({
            content: groupId,
            id: groupId,
            style: "stroke:" + arr_color[properties],
            options: {
                shaded: {
                    orientation: "bottom",
                    style: "fill:" + arr_color[properties]
                },
                drawPoints: {
                    styles: "stroke:" + arr_color[properties] + ";fill:" + arr_color[properties]
                }
            }
        });
        items[i].group = groupId;
        scope.labels[properties].max = Number(items[i].y).toFixed(1);
        scope.labels[properties].min = Number(items[i].y).toFixed(1);
    } else {
        if (items[i].label.className == items[i - 1].label.className) {
            if (items[i].x.getTime() - items[i - 1].x.getTime() > Number(type[1]) * 60 * 1000) {
                groupId++;
                groups.add({
                    content: groupId,
                    id: groupId,
                    style: "stroke:" + arr_color[properties],
                    options: {
                        shaded: {
                            orientation: "bottom",
                            style: "fill:" + arr_color[properties]
                        },
                        drawPoints: {
                            styles: "stroke:" + arr_color[properties] + ";fill:" + arr_color[properties]
                        }
                    }
                });
            }
            items[i].group = groupId;
            scope.labels[properties].max = Math.max(scope.labels[properties].max, Number(items[i].y)).toFixed(1);
            scope.labels[properties].min = Math.min(scope.labels[properties].min, Number(items[i].y)).toFixed(1);
        } else {
            groupId++;
            properties++;
            groups.add({
                content: groupId,
                id: groupId,
                style: "stroke:" + arr_color[properties],
                options: {
                    shaded: {
                        orientation: "bottom",
                        style: "fill:" + arr_color[properties]
                    },
                    drawPoints: {
                        styles: "stroke:" + arr_color[properties] + ";fill:" + arr_color[properties]
                    }
                }
            });
            items[i].group = groupId;
            scope.labels[properties].max = Number(items[i].y).toFixed(1);
            scope.labels[properties].min = Number(items[i].y).toFixed(1);
        }
    }
}

var container = document.getElementById("graph");
container.innerHTML = "";

var dataset = new vis.DataSet(items);

var options = {
    dataAxis: {
        left: {
            format: function (value) {
                return Number(value).toFixed(1);
            }
        }
    },
    drawPoints: {
        style: "circle"
    },
    orientation: "top",
    showCurrentTime: true,
    end: new Date(end),
    max: new Date(end),
    min: new Date(start),
    start: new Date(start)
};

startTime = options.start.getTime();
endTime = options.end.getTime();
var graph2d = new vis.Graph2d(container, dataset, groups, options);