为什么jqPlot的DateAxisRenderer在显示单个数据点时会崩溃?

时间:2022-09-15 10:52:46

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:

我已经用jqPlot隔离了一个结束案例,导致它“崩溃”(无限期地停止)我的整个页面的javascript。当我在带有单个值的折线图中使用DateAxisRenderer时会发生这种情况:

(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?

为什么会这样?这是jqPlot中的错误还是我做错了什么?

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.

我正在使用jQuery v1.6.4,jqPlot v1.0.0b2_r1012并在Firefox 8.0.1上呈现。

2 个解决方案

#1


6  

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".

瞥见DateAxisRenderer的代码表明插件试图计算最小值和最大值以确定滴答。这只是表明作者暗示一个系列至少包含两个数据点。这在文档中没有说明,或者在代码中检查了插件“崩溃”的原因。

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

在jqplot错误跟踪列表中已经提交了错误(4天前,2012年1月21日)。

#2


0  

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

我今天也遇到过这个问题,让我感到惊讶的是我使用jsfiddle的相同代码,我使用了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.

我正在使用jqplot与ASP.NET MVC并使用nuget扩展下载了jqplot脚本,结果发现扩展已经下载了导致问题的旧版jqplot。

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.

因此,只需将旧的DateAxisRender.js从此处更改为新的更新,解决了我的问题,或者您也可以从此页面下载最新版本。

I had created a demo at jsfiddle

我在jsfiddle创建了一个demo

#1


6  

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".

瞥见DateAxisRenderer的代码表明插件试图计算最小值和最大值以确定滴答。这只是表明作者暗示一个系列至少包含两个数据点。这在文档中没有说明,或者在代码中检查了插件“崩溃”的原因。

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

在jqplot错误跟踪列表中已经提交了错误(4天前,2012年1月21日)。

#2


0  

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

我今天也遇到过这个问题,让我感到惊讶的是我使用jsfiddle的相同代码,我使用了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.

我正在使用jqplot与ASP.NET MVC并使用nuget扩展下载了jqplot脚本,结果发现扩展已经下载了导致问题的旧版jqplot。

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.

因此,只需将旧的DateAxisRender.js从此处更改为新的更新,解决了我的问题,或者您也可以从此页面下载最新版本。

I had created a demo at jsfiddle

我在jsfiddle创建了一个demo