2
votes

According to the flot documentation (https://github.com/flot/flot/blob/master/API.md):

"The options "min"/"max" are the precise minimum/maximum value on the scale. If you don't specify either of them, a value will automatically be chosen based on the minimum/maximum data values."

I am specifying min and max values, yet the graphs that are being generated are still automatically chosen based on the minimum/maximum data values (var d1) rather than the specified min and max values.

Here is my code:

var i = 0;
while (i < myarray.length) { // length of myarray is 3, hence 3 graphs are produced
        // generate date object from date and time strings in array
        startTime = new Date(myarray[i].date[0] +'T' + myarray[i].time[0] + ':00');

        // generate timestamp from date object
        startTime = startTime.getTime();

        endTime = new Date(myarray[i].date[1] +'T' + myarray[i].time[1] + ':00');
        endTime = endTime.getTime();

        var d1 = [[startTime, 0], [(((endTime - startTime)/2) + startTime), 1], [endTime, 0]];

        var options = { series: { curvedLines: { active: true }}};

        // min is the time 2014-11-20, 3 AM (timestamp: 1416453000000)
        // max is the time 2014-11-20, 11 PM (timestamp: 1416525000000)
        $.plot($("#" + i), [{data: d1, xaxis: {min: (new Date('2014-11-20T03:00:00')).getTime(), max: (new Date('2014-11-20T23:00:00')).getTime(), mode: "time", twelveHourClock: true, timeformat: "%I:%M"}, lines: { show: true}, curvedLines: {apply: true}}], options);

         i++;
        }

The graphs end up looking like this (notice all have different min and max values):

Graph 1

Graph 2

Graph 3

P.S. The Flot time series plugin doesn't seem to be working either since the x axis points are showing up as timestamps and not in the "hour:minutes" (%I:%M) format as specified.

1

1 Answers

2
votes

If you look at their time example they're putting the xaxis config in the options (so the third argument) and not included with the graph data (second argument) like you are:

$.plot("#placeholder", [d], {
            xaxis: {
                mode: "time",
                minTickSize: [1, "quarter"],
                min: (new Date(1999, 0, 1)).getTime(),
                max: (new Date(2000, 0, 1)).getTime()
            }
        });