2

I'm working with flotchart to make a custom linechart (which is call in ajax) but I'm probably doing something wrong because he will not be displayed and i get the error :

Uncaught Error: Time mode requires the flot.time plugin.

But the jquery.flot.time.js is included so I don't understand why i got this error.

I found this link : https://github.com/flot/flot/issues/1016 which explain why flot is throwing this error but I don't understand everything...

Can someone explain to me more easily or just check what is wrong in my code ?

$(function() {
    var data = [
        {
        label: "A0-P1-M1 10cm", 
        data: 
            [
                [1388538000000, 29.8848],
                [ // .. some data]
            ]
        }
    ];
    var options = {
        legend: {
            noColumns: 1
        },
        xaxis: {
            mode: "time",
            timeformat: "%d/%m %H:%M",
            tickLength: 10
        },
        yaxis: {
            show: false
        }
    };
    var plot = $.plot("#placeholder13", data, options);
});

Thank you for your time & help. Sorry for my english.

hidewak
  • 299
  • 1
  • 4
  • 16

4 Answers4

2

As the error says, you're not including the time plugin. Make sure your include path is correct, and that you're including the plugin after you include Flot itself.

Since the problem is with your includes, we would need to see your HTML in order to be more specific.

DNS
  • 37,249
  • 18
  • 95
  • 132
1

I had this error with that code :

jQuery.getScript("jquery.flot.min.js");
jQuery.getScript("jquery.flot.time.min.js");

Fixed with that to respect loading order :

jQuery.getScript("jquery.flot.min.js",function(){
    jQuery.getScript("jquery.flot.time.min.js")
});
Jacques
  • 38
  • 7
0

As you said this was supposedly resolved with check-in 1016 which is in a recent build if you go out to down load it. Contrary to what @DNS said, this is thrown from inside another file and has little to do with whether or not you're including the flot.time.js file. The fix is in that file (so you have obviously need to include it properly), but it still wouldn't work with the code you posted... The way to fix the code is to simply add { } around your series:

    var data = [
        {
        label: "A0-P1-M1 10cm", 
        data: 
            [
                [1388538000000, 29.8848],
                [ // .. some data]
            ]
        }
    ];
    //Becomes:
    var data = [
        {
        label: "A0-P1-M1 10cm", 
        data: 
            [  
                {   //<---Attention!
                    [1388538000000, 29.8848],
                    [ // .. some data]
                }   //<---Attention!
            ]
        }
    ];

... In general the problem that this is describing is that the Flot API cannot determine where your series are inside your data (or even if you have any series) and it interprets this ..um.. Poorly..

But I thnk you for your post it helped me find my problem.. Cheers..

0

This probably won't solve your problem, but it may help others.

I noticed that to change the chart options after creating the chart that I needed to do chart.getOptions().xaxis.whatever AND chart.getOptions().xaxes[0].whatever. So I started with the plan of doing all the options dynamically and latter changed it by doing a copy and paste...

jQuery(...).plot(..., ..., {
  ...,
  xaxis: {
    aFewOptions: ...,
    ...
  },
  xaxes: {
    '0': {
      theSameFewOptions: ...,
      ...
    }
  }
});

the whole xaxes[0] shouldn't be included when first creating the chart, even if it is required latter...

doing something like this will cause

Uncaught Error: Time mode requires the flot.time plugin.

even if the flot.time plugin is loaded...

my mistake was copying and pasting code I shouldn't of... doesn't look like you did anything like this though...

user3338098
  • 907
  • 1
  • 17
  • 38