D3 - data format required for cal-heatmap calendar heatmap?

I am trying to build calendar-heatmapfrom a link .

I searched all the documentation but could not find the sample file for data-format.

Here is a link for documentation, but there is no sample file for it.

In the documentation, I find that this data is being imported datas-years.json. But I do not know how the format is. Someone please help me with this.

+4
source share
4 answers

Cal-Heatmap expects data in a JSON object in the following format:

{
    "timestamp1": value1,
    "timestamp2": value2,
    "timestamp3": value3,
    ...
}

The value can be any number (integer or float).

. - "UTC seconds" ( " " " unix" ) 01-01-1970 00:00:00 / GMT GMT. UTC.

1.388.000.000 UTC . 2000 , UTC 946 000 000, JSON.

, , UTC , , Cal-Heatmap.:)

+3

json .

: 12 , . start → point it 11 , json .

var data = generateRandomData();

            function getRandomInt(min, max) {
                return Math.floor(Math.random() * (max - min + 1)) + min;
            }


            function generateRandomData(){
                var date = new Date();

                var mind = date.valueOf();
                var maxd = date.setMonth(date.getMonth() - 11);

                var mins = 0;
                var maxs = 40;

                var retobj = {};

                for(var i=0;i<100;i++){
                    retobj[getRandomInt(mind,maxd)/1000] = getRandomInt(mins,maxs);
                }

                return retobj;
            }
+1

Cal-heatmap JSON

{
    "timestamp1": value1,
    "timestamp2": value2,
    "timestamp3": value3,
    ...
}

, , ( javascript).

, data javascript:

var d = {946705035: 25};
var cal = new CalHeatMap();
cal.init({data: d}); // For variable
cal.init({data: "path/to/file.json"}) // For file, or URI

Cal-heatmap CSV TSV.

, cal-heatmap / :

javascript JSON, Cal-heatmap

/uri

datatype, afterLoadData(), json.

datatype , . json, csv tsv , json .. Else, txt, .

Google Analytics, data, datatype afterLoadData().

0

All Articles