Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 重新绘制ajax成功的Jqplot_Javascript_Jquery_Ajax_Json_Jqplot - Fatal编程技术网

Javascript 重新绘制ajax成功的Jqplot

Javascript 重新绘制ajax成功的Jqplot,javascript,jquery,ajax,json,jqplot,Javascript,Jquery,Ajax,Json,Jqplot,我使用这段代码使用AJAX JSON数据呈现器创建一个Jqplot。一切正常。我在页面上有一个按钮,允许用户输入一个新值(通过ajax更新)。这将被存储到数据库中(与json数据来自的位置相同) 我希望在按下按钮并将新值添加到数据库中时再次刷新jqplot(即检查ajax源代码) 我尝试了几种方法,它们要么不更新图形,要么在彼此的顶部绘制图形 $(document).ready(function(){ // Our ajax data renderer which here retrieve

我使用这段代码使用AJAX JSON数据呈现器创建一个Jqplot。一切正常。我在页面上有一个按钮,允许用户输入一个新值(通过ajax更新)。这将被存储到数据库中(与json数据来自的位置相同)

我希望在按下按钮并将新值添加到数据库中时再次刷新jqplot(即检查ajax源代码)

我尝试了几种方法,它们要么不更新图形,要么在彼此的顶部绘制图形

$(document).ready(function(){
  // 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 plot2 = $.jqplot('chart2', jsonurl,{
    title: "AJAX JSON Data Renderer",
    dataRenderer: ajaxDataRenderer,
    dataRendererOptions: {
      unusedOptionalUrl: jsonurl
    }
  });
});
假设我需要将jqplot添加到函数中并销毁旧的绘图,然后在成功时调用该函数?-不过,用那种方法是不能使事情正常进行的

任何帮助都会很好


谢谢

您是否尝试重新绘制图表

var plot2 = $.jqplot('chart2', jsonurl,{
      title: "AJAX JSON Data Renderer",
      dataRenderer: ajaxDataRenderer,
      dataRendererOptions: {
      unusedOptionalUrl: jsonurl
    }
});

plot2.replot();
希望能有帮助

问候,,
Anish

你试过使用它吗。我真的建议您不要使用async:false ajax请求,您可以通过将plot2=$.jqplot块移动到ajax请求的success函数中来实现。redraw主要用于缩放。jqplot建议使用ajax JSON数据呈现器。我在同一页上运行了多个图表,它们使用相同的dataRenderer。如果在ajax上成功的话,肯定会变得一团糟吗?