Here is an example that converts time spans into time points that can then be consumed by the TimeChart:
http://jsfiddle.net/gbswvnfh/
let eventData = [
[+moment.utc("2016-01-01 00:00:00"), +moment.utc("2016-01-03 23:59:59.999"), 7],
[+moment.utc("2016-01-02 04:00:00"), +moment.utc("2016-01-03 10:59:59.999"), 5],
[+moment.utc("2016-01-01 19:23:00"), +moment.utc("2016-01-03 12:01:01.999"), 4],
];
var chart = new ZoomCharts.TimeChart({
container: "demo",
data: [{
// since "useSmallerUnitCache" is false, the "units" must contain all
// possible display units
units: ["y", "M", "d", "6 h", "h"],
useSmallerUnitCache: false,
dataFunction: (from, to, unit, success, fail) => {
let data = convertEventsToTimePoints(eventData, unit);
success(data);
}
}],
navigation: {
initialDisplayPeriod: +moment.utc("2016-01-01") + " > " + (+moment.utc("2016-01-04")) ,
initialDisplayUnit: "1 h"
}
});
function convertEventsToTimePoints(events: Array<[number, number, number]>, unit: string) {
// The first day of the week. `0` - Sunday, `1` - Monday.
let stepSettings = { week: { dow: 1 } };
// use the internal TimeStep class that knows how to handle units like "6 h",
// and can be used to split the event time span into intervals based on this unit
let step = ZoomCharts.Internal.TimeChart.TimeStep.parse(unit);
// the data array that will contain the events as time points
// the first item is the timestamp, the second is the sum of values
let res: Array<[number, number]> = new Array(0);
// map from timestamp to the index in the data array
let map: ZoomCharts.NumberDictionary<number> = Object.create(null);
for (let e of events) {
let start: number = step.roundTimeDown(e[0], stepSettings);
let end: number = step.roundTimeUp(e[1], stepSettings);
let val: number = e[2];
for (let time = start; time < end; time = step.add(time)) {
let idx = map[time];
if (idx === void 0) {
map[time] = idx = res.length;
res.push([time, val]);
} else {
res[idx][1] += val;
}
}
}
res.sort((a,b) => { return a[0] - b[0]; });
if (res.length === 0) {
throw new Error("Assert: empty result after converting events");
}
return <ZoomCharts.Configuration.TimeChartDataObject>{
unit: unit,
values: res,
from: res[0][0],
to: step.add(res[res.length - 1][0])
};
}