0

I'm trying to use jquery.flot.js with jquery.flot.time.js plugin in order to setup a graph with years date on xaxis.

It's a simple graph, with two lines, each of them has a point for year 2014 and a second one for year 2015.

But I'm unabled to have correct time in xaxis legend: only 2015 is displayed, and not at the correct place:

enter image description here

I'm using simple data to generate the graph, with an interval of 1 year. My datetime is generated using javascript:

var date14 = new Date(2014, 1, 1, 1).getTime();
var date15 = new Date(2015, 1, 1, 1).getTime();
var data = {
    { label="Orders", data=[[date14, 51], [date15, 92]] }, 
    { label="Products", data=[[date14, 69], [date15, 121]] }
};

var options = {
        series: {
            lines: { show: true },
            points: { show: true }
        },
        yaxis: {
            minTickSize: 1
        },
        xaxis: {
             mode: 'time',
             timeformat: '%y',
             tickSize: [1, 'year']
        },
    };

$.plot('#container1', data, options);

Any idea how to proceed to get a correct date xaxis legend with 2014 and 2015 on good position?

j08691
  • 204,283
  • 31
  • 260
  • 272
DrÿSs'
  • 41
  • 1
  • 6

1 Answers1

0

Ok I've found the answer: in Javascript, first month begins at 0, not at 1.

So generated date must be:

var date14 = new Date(2014, 0, 1, 1).getTime();
var date15 = new Date(2015, 0, 1, 1).getTime();
DrÿSs'
  • 41
  • 1
  • 6