Why does my cal-heatmap not not display data -
i have cal-heatmap below (+see jsbin) i'm trying color using data.
var data = {"63556099200":2,"63556185600":4,"63556272000":2,"63556358400":1,"63556704000":2,"63556790400":1,"63556876800":1,"63556963200":1,"63557222400":1,"63557308800":1,"63557827200":1,"63557913600":1,"63558000000":2,"63558086400":1,"63558172800":1,"63559296000":3,"63559728000":2,"63559814400":1,"63559900800":3,"63559987200":1,"63560246400":2,"63560332800":1,"63560419200":2,"63560505600":2,"63560592000":1,"63560937600":1,"63561456000":4,"63561801600":2,"63562060800":2,"63562147200":1,"63562233600":2,"63562320000":1,"63562406400":1,"63562665600":1,"63562752000":1,"63562838400":2,"63562924800":1,"63563270400":2,"63563961600":2,"63564048000":2,"63564134400":3,"63564220800":3,"63564566400":2,"63564739200":2,"63564825600":1,"63565084800":2,"63565171200":1,"63565257600":2,"63565344000":2,"63565430400":3}; var cal = new calheatmap(); cal.init({ itemselector: "#cal", data: data, itemname: ["visit", "visits"], considermissingdataaszero: true, legend: [1, 2, 3, 4], cellsize: 17, cellpadding: 2, domain: "month", domaingutter: 10, domaindynamicdimension: false, domainlabelformat: function (date) { return moment(date).format("mmm, yyyy").touppercase(); }, subdomain: "x_day", subdomaintextformat: "%d", range: 12, start: new date(2015, 0, 1) });
http://jsbin.com/yixuja/12/edit?html,output
the cal-heatmap seem not recognize data correctly formatted. missing?
it turned out timestamps in data not representation of seconds since 1970-jan-1.
correct data:
data = {"1420498800":2,"1420585200":4,"1420671600":2,"1420758000":1,"1421103600":2,"1421190000":1,"1421276400":1,"1421362800":1,"1421622000":1,"1421708400":1,"1422226800":1,"1422313200":1,"1422399600":2,"1422486000":1,"1422572400":1,"1423695600":3,"1424127600":2,"1424214000":1,"1424300400":3,"1424386800":1,"1424646000":2,"1424732400":1,"1424818800":2,"1424905200":2,"1424991600":1,"1425337200":1,"1425855600":4,"1426201200":2,"1426460400":2,"1426546800":1,"1426633200":2,"1426719600":1,"1426806000":1,"1427065200":1,"1427151600":1,"1427238000":2,"1427324400":1,"1427670000":2,"1428361200":2,"1428447600":2,"1428534000":3,"1428620400":3,"1428966000":2,"1429138800":2,"1429225200":1,"1429484400":2,"1429570800":1,"1429657200":2,"1429743600":2,"1429830000":3};
http://jsbin.com/yixuja/15/edit?html,output
the linq (using linqpad) use cal-heatmap needed dataformat: (see how export data linqpad json? how linqpad produce json)
int userid = 4; datetime start = new datetime(2015, 1 , 2); datetime end = new datetime(2015, 6, 30); // group datetime (yyyy-mm-dd hh:mm:ss) values date (yyyy-mm-dd) group , count aggregate // timestamp representation of date // serialize cal-heatmap json data via .todictionary var result = (from r in response (r.respondentuserid == userid) && (r.responsebegin >= start) && (r.responsebegin <= end) group r new { date = r.responsebegin.date } grp select new { timestamp = grp.key.date, reports = grp.count() }) .tolist() .select (r => new { timestamp = (r.timestamp - new datetime(1970, 1, 1).tolocaltime()).totalseconds, r.reports }) .todictionary (r => r.timestamp.tostring(), r => r.reports); new javascriptserializer().serialize(result).dump();
Comments
Post a Comment