Fleet chart tooltip error - One-day tooltip date behind the X-Axis axis

I could not understand why the tooltip date is off for one day. I believe the X axis is correct, and I played with it, but it kills me.

How can i fix this?

I am passing JSON from the URL endpoint to the jsonDataUrl variable. Here is an example datapoint:[{date: "2013-01-01", value: 50}]

And cssSelector is just a placeholder.

Here is my code:

  $.getJSON(jsonDataUrl, function(res) {
   var data = [];
    $.each(res, function(i, entry){
      data.push( [new Date(entry["date"]), entry["value"]] );
    });

    var opts = { yaxis: { min: 0},
                 xaxis: { mode: "time", timeformat: "%m-%d"},

                 series: { lines: { show: true }, points: { show: true } },

                 grid: {hoverable: true, clickable: true}
    };

    $.plot($(cssSelector), [data], opts);

    $(cssSelector).bind("plotclick", function(event, pos, item) {
        if (item) {

            var x = parseInt(item.datapoint[0]),
                y = item.datapoint[1];
            var date = (new Date(x));
            var day = date.getDate();
            var month = date.getMonth() + 1;
            var formattedDate = month + "-" + day;

            $("#tooltip").remove();
            var label = "date: " + formattedDate + "<br/> count: " + y;
            showTooltip(item.pageX, item.pageY, label);
        }
    });
  });
+5
source share
1 answer

, , . , ! Ruby on Rails URL- JSON. UTC, , .

, date.getDate() date.getMonth() date.getUTCDate() date.getUTCMonth().

+4

All Articles