用json数据更新jqPlot(闪烁)

时间:2014-01-17 04:01:39

标签: json jqplot

所以我把它放在互联网上的一堆例子中。我从文本文件中提取数据并使用jqPlot进行绘图。然后我回想起一个函数来不断更新文件中的图:

<div id="chart1" style="height:300px; width:500px;"></div>
<script class="code" type="text/javascript">


  // Our ajax data renderer which here retrieves a text file.
  // it could contact any source and pull data, however.
  // The options argument isn't used in this renderer.
  var ajaxDataRenderer = function(url, plot, options) {
        var ret = null;
    $.ajax({
            // have to use synchronous here, else the function 
        // will return before the data is fetched
        async: false,
        url: url,
        dataType:"json",
        success: function(data) {
             ret = data;
        }
        });
    return ret;
  };

  // The url for our json data
  var jsonurl = "./jsondata.txt";

  // passing in the url string as the jqPlot data argument is a handy
  // shortcut for our renderer.  You could also have used the
  // "dataRendererOptions" option to pass in the url.
  var plot1;



$(document).ready(function(){

  plot1 = $.jqplot('chart1', jsonurl,{
    title: "MY GRAPH",
    dataRenderer: ajaxDataRenderer,
    dataRendererOptions: {
        unusedOptionalUrl: jsonurl
        }
  });

    ConstantPlotter();
});


function ConstantPlotter() {

  plot1.destroy();
  plot1 = $.jqplot('chart1', jsonurl,{
    title: "MY GRAPH",
    dataRenderer: ajaxDataRenderer,
    dataRendererOptions: {
        unusedOptionalUrl: jsonurl
        }
  });

  setTimeout(ConstantPlotter,100)
}

</script>

它工作正常,但由于它每次被破坏和重建,情节都会严重闪烁。问题是当我尝试用

替换'破坏和绘图'代码时
plot1 = $.jqplot('chart1', jsonurl,{
    title: "MY GRAPH",
    dataRenderer: ajaxDataRenderer,
    dataRendererOptions: {
        unusedOptionalUrl: jsonurl
        }
  }).replot();

它工作得很漂亮,但我得到了可怕的内存泄漏。

有没有人知道如何从文件中不断更新此图而不会出现可怕的闪烁?谢谢!

0 个答案:

没有答案
相关问题