首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ajax上重新绘制Jqplot成功

在ajax上重新绘制Jqplot成功
EN

Stack Overflow用户
提问于 2014-03-04 22:48:30
回答 1查看 401关注 0票数 1

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

当按钮被按下并且新值已添加到数据库时,我希望jqplot再次刷新(即检查ajax源)。

我尝试了一些方法,这些方法要么不更新图形,要么将图形绘制在彼此的顶部。

代码语言:javascript
复制
$(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添加到一个函数中并销毁旧的plot,然后在成功时调用该函数?-使用这种方法不能让事情正常工作。

任何帮助都是最好的。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2014-04-11 13:35:59

你有没有试着重新绘制图表?

代码语言:javascript
复制
var plot2 = $.jqplot('chart2', jsonurl,{
      title: "AJAX JSON Data Renderer",
      dataRenderer: ajaxDataRenderer,
      dataRendererOptions: {
      unusedOptionalUrl: jsonurl
    }
});

plot2.replot();

希望能有所帮助。

你好,阿尼什

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22175157

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档