Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does jqPlot's DateAxisRenderer crash when showing a single data point?

Tags:

jquery

jqplot

I've isolated an end case with jqPlot that causes it to "crash" (halt indefinitely) my entire page's javascript. This happens when I use the DateAxisRenderer in a line chart with a single value like so:

(function() {
  $(function() {
    var data, now, plot1;
    now = new Date;
    // single data point in the series:
    data = [[now, 1]];
    return plot1 = $.jqplot("plotTarget", [data], {
      axes: {
        xaxis: {
          // if I remove this renderer, the "crash" does not happen:
          renderer: $.jqplot.DateAxisRenderer
        }
      }
    });
  });
}).call(this);

Why does this happen? is this a bug in jqPlot or am I doing something wrong?

Also noticed: If I add more values with the same date into the series, the same problem occurs. If I add more values with different dates, the problem goes away.

I'm using jQuery v1.6.4, jqPlot v1.0.0b2_r1012 and rendering on Firefox 8.0.1.

like image 608
urig Avatar asked Dec 21 '11 10:12

urig


2 Answers

Glimpsing at the code of the DateAxisRenderer shows that the plugin tries to compute a minimum and maximum value to determine the ticks. This simply suggests that the author implies that a series consists of a minimum of two datapoints. And this is not stated in the docs or checked in the code thats why the plugin "crashes".

In the jqplot Bugtracking list the bug is already filed (4 days ago on Jan 21st 2012).

like image 158
dgw Avatar answered Nov 15 '22 20:11

dgw


I also had faced this issue today, what surprised me was the same code worked with jsfiddle where I used scripts from Bitbucket.

I was using jqplot with ASP.NET MVC and had downloaded the jqplot scripts using nuget extension, it turned out that extension had downloaded the older version of jqplot which caused the problem.

So, simply changing my old DateAxisRender.js to the new updated one from here, solved my problem or you can also download the latest version from this page.

I had created a demo at jsfiddle

like image 42
Yasser Shaikh Avatar answered Nov 15 '22 20:11

Yasser Shaikh