1
我正在使用此代码使用AJAX JSON数据呈现器创建Jqplot。它一切正常。我在页面上有一个按钮,允许用户输入一个新值(通过ajax更新)。这被存储到数据库中(与json数据来自同一个地方)。在ajax成功上重新绘制Jqplot
当按下按钮并将新值添加到数据库时,我希望再次刷新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添加到函数中并销毁旧图,然后调用成功函数? - 不能很好地使用该方法正常工作。
任何帮助将是伟大的。
谢谢
您是否尝试过使用[jqPlot.reDraw(http://www.jqplot.com/docs/files/jqplot-core-js.html#jqPlot.redraw)。我真的建议你不要使用async:false ajax请求,你可以通过在ajax请求的成功函数中移动plot2 = $ .jqplot片来使它工作。 – JoseM
重绘主要用于缩放。 –
ajax JSON数据呈现器是jqplot推荐的。 http://www.jqplot.com/tests/data-renderers.php我有在同一页上运行多个图表使用相同的dataRenderer。如果是在ajax成功的情况下完成,那么是否会收到messey? –