Timeline: Invalid start "NaN" with timechange/timechanged event listeners
Asked Answered
K

1

6

I'm having an issue when trying to wire into the timechange or timechanged event handlers. I receive a Invalid start "NaN" error which appears to be being caused by adding a custom timebar...

Below is a sample of my code...

timeline.setOptions({
    height: '100%',
    editable: false,
    moveable: true,
    zoomable: true,
    configure: true,
    showCurrentTime: false,
    start: vis.moment.utc().format('YYYY-MM-DDT00:00:00.000Z',
    moment: function(date) {
      return vis.moment(date).utc();
     }
});

timeline.addCustomTime(vis.moment.utc().valueOf(), 'my-time-bar');
timeline.on('timechanged', function(props) {
     console.log('timechanged...');
});

If I comment out the timeline.on('timechanged') line I do not receive the error and all renders correctly. I receive the error in both Chrome and FireFox.

Kerley answered 20/3, 2018 at 9:21 Comment(0)
G
0

I have never used vis.js. So I'm just speculating after reading the docs of timeline.

First issue: I think that there is a clothing-bracket missing right before the comma in your options at the line of start:

Have a look at: start: vis.moment.utc().format('YYYY-MM-DDT00:00:00.000Z', vs. start: vis.moment.utc().format('YYYY-MM-DDT00:00:00.000Z'),

BTW. I don't understand why you are specifying the format of the start time - is this really necessary?

Second issue: timechangedseems to return 3 properties (docs): id, time, event

So the event-listeners callback function should be probably changed to:

timeline.on('timechanged', function(id, time, event) {
     console.log('timechanged...');
});
Glaucoma answered 31/3, 2018 at 15:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.