I use the SMILES timeline loading event data as JSON from file and as variable.
Loading from file works fine using the samplecode from the homepage:
tl = Timeline.create(document.getElementById("div-timeline"), bandInfos);
Timeline.loadJSON("js/timelinedata.json", function(json, url) {
eventSource.loadJSON(json, url); });
Here is the content of my file timelinedata.json:
{"dateTimeFormat": "iso8601",
"events" : [
{"start": "1924",
"title": "Barfusserkirche",
"description": "by Lyonel Feininger, American/German Painter, 1871-1956",
"image": "link to an image",
"link": "link to an article"
}
]}
However when i paste the JSON into a var and try to load it i get complains.
This is how i populate my var:
function TimeTestData1(){
var TimelineEvent = {"dateTimeFormat": "iso8601",
"events" : [
{"start": "1924",
"title": "Barfusserkirche",
"description": "by Lyonel Feininger, American/German Painter, 1871-1956",
"image": "link to an image",
"link": "link to an article"
}
]};
return TimelineEvent;
}
And use it in timeline:
var tdata = TimeTestData1();
console.dir(tdata); // this looks fine
// [ timeline code ]
Timeline.loadJSON(tdata, function(json, url) { eventSource.loadJSON(json, url); });
I get an "alert" popup with the message:
Failed to load json data from [object Object] Not Found
When i use JSON.stringify(tdata)
like this:
Timeline.loadJSON(JSON.stringify(tdata), function(json, url) {
eventSource.loadJSON(json, url); });
The browser tells me (using alert popup):
Failed to load json data from {"dateTimeFormat":"iso8601","events":[{"start":1924,"title":"Barfusserkirche","description":"by Lyonel Feininger, American/German Painter, 1871-1956","image":"link to an image","link":"link to an article"}]} Not Found
here is the complete code of the timeline function:
function LoadTimeline() {
var tl;
var eventSource = new Timeline.DefaultEventSource(0);
//var tdata = TimeTestData1();
var theme = Timeline.ClassicTheme.create();
theme.timeline_start = new Date(Date.UTC(1890, 0, 1));
theme.timeline_stop = new Date(Date.UTC(2020, 0, 1));
var d = Timeline.DateTime.parseGregorianDateTime("1950") // set date to display
var bandInfos = [
Timeline.createBandInfo({
width: "70%",
intervalUnit: Timeline.DateTime.YEAR,
intervalPixels: 100,
eventSource: eventSource,
date: d
}),
Timeline.createBandInfo({
width: "30%",
intervalUnit: Timeline.DateTime.CENTURY,
eventSource: eventSource,
date: d,
intervalPixels: 200
})
];
bandInfos[1].syncWith = 0;
bandInfos[1].highlight = true;
tl = Timeline.create(document.getElementById("div-timeline"), bandInfos);
Timeline.loadJSON("js/timelinedata.json", function(json, url) {
eventSource.loadJSON(json, url); });
} //JSON.stringify(tdata) or tdata or "js/timelinedata.json"
How do I have to pass my event json var so timeline eats it?