2

I have an array of Javascript datetime objects which I want to display on a cal-heatmap. For this, i've done the following:

var startTimes = [] //array of datetimes to show
var cal = new CalHeatMap();
cal.init({
    itemSelector: '.heat-map',
    domain: 'day',
    subDomain: 'hour',
    range: range,
    start: new Date(startTimes[0]),
    highlight: new Date(startTimes[0])
});

for (s in startTimes) {
    cal.highlight(cal.options.highlight.push(new Date(startTimes[s])));
}

This however, doesn't seem to work as only the first date gets marked.

Newtt
  • 6,050
  • 13
  • 68
  • 106

1 Answers1

0

Note that push returns the new length of the array and not the element you just added to it.

According to this and the doc of cal-heatmap/#highlight which states that the method expects a date, I guess your code should be:

for (s in startTimes) {
    var date = new Date(startTimes[s]);
    cal.options.highlight.push(date);
    cal.highlight(date);
}
  • 1
    Sorry, forgot to review this. What worked is adding the datetimeobjects into a single array and using those to show in the `data` parameter of the heatmap. :) – Newtt Jul 08 '15 at 16:24