如果数据为空,则Vis.js时间轴不可见

时间:2018-09-28 12:54:17

标签: javascript jquery vis.js

我是Vis.js的新手,遇到了麻烦... 当我没有数据时,不存在时间轴,而是将时间轴留空。 在3.10.0版本中可以使用,但在4.21.0版本中不能使用

我希望一切变得清晰...我在这里举了一个例子:

exports.timeline = function(req, res) {
    var Followers = mongoose.model('Follow');
    Followers.find({'follower': req.user.username}, function(err, followerResult) {
        var name = [req.user.username];
        var books = [];

        function addName(username) {
            name.push(username);
        }

        for(var user in followerResult) {
            addName(followerResult[user]['followed']);
        }

        let count = 0;
        for(var usernames in name) {
            function getCallback(callbackTrash) {
                var Books = mongoose.model('Book');
                Books.find({'username': name[usernames]}, function (err, loadOfBollocks) {
                    count++;
                    callbackTrash(loadOfBollocks);
                    if(count == name.length){
                        console.log(books);
                        res.send(books);
                    }
                });
            }

            getCallback(function(result) {
                books.push(result);
            });
        }
    });
}
function setTable(){
      var select = document.getElementById("select");
      var value = select.options[select.selectedIndex].value;
      var container = document.getElementById('mytimeline');
      container.innerHTML = "";
      
      if(value=="full"){
          var items = new vis.DataSet([
            {id: 1, group: 1, content: 'item 1', start: '2013-04-20'},
            {id: 2, group: 2, content: 'item 2', start: '2013-04-14'},
            {id: 3, group: 3, content: 'item 3', start: '2013-04-18'},
            {id: 4, group: 3, content: 'item 4', start: '2013-04-16', end: '2013-04-19'},
            {id: 5, group: 1, content: 'item 5', start: '2013-04-25'},
            {id: 6, group: 1, content: 'item 6', start: '2013-04-27'}
          ]);

          var groups = new vis.DataSet([
            {id: 1, content: 'aaa'},
            {id: 2, content: 'bbb'},
            {id: 3, content: 'ccc'},
            {id: 4, content: 'ddd'}
          ]);
          var options = {};
          var timeline = new vis.Timeline(container, items, groups, options);
      }else if(value=="empty"){
          var items = new vis.DataSet();
          var groups = new vis.DataSet();
          var options = {};
          var timeline = new vis.Timeline(container, items, groups, options);
          
        	alert("don't work... \n I would like to have an empty TimeLine... not a \nLike I have do it in oldest version (3.10.0)\nhttp://jsfiddle.net/n427qjLm/2/");
      }
    }
    #mytimeline{
      border:1px solid gray;
      padding : 5px;
    }
    .vis.timeline .labelset .vlabel .inner {
      min-height: 100px;
    }

1 个答案:

答案 0 :(得分:1)

想要空的时间轴时,必须在选项中指定“开始”:

var options = { start: '2018-08-20' };