I think the following question (JQPlot auto refresh chart with dynamic ajax data) comes close to what I would like to achieve. Problem is that my knowledge of js is very limited so I find it very hard to understand.

我认为以下问题(带有动态ajax数据的JQPlot自动刷新图表)接近我想要实现的目标。问题是我对js的了解非常有限,所以我觉得很难理解。

The situation is like this: I plot a jqplot graph that is generated using a json file. I would like to update the graph without having to refresh the page. In order to plot the graph right I determin some parameters using php inside the javascript (such as the max and min limits for the xaxis and yaxis).

情况是这样的:我绘制了一个使用json文件生成的jqplot图。我想更新图表而不必刷新页面。为了正确绘制图形,我在javascript中使用php确定了一些参数(例如xaxis和yaxis的最大和最小限制)。

my (simplified) js to plot the graph looks like this:

我的(简化)js绘制图形看起来像这样:

var plot = $.jqplot('chartdiv',  [<?php echo $alllines;?>] ,   
    {
        seriesColors: ["#FAB534", "#9495E0", "#75E07E", "#F558F5", "#00EEFF", "#F558F5"],

        axes:{
            xaxis:{
                renderer:$.jqplot.DateAxisRenderer,
                tickInterval: '1 minute',                   
                min:'<?php echo $startlimit ?>',
                max:'<?php echo $endlimit ?>'
            },

            yaxis:{
                tickInterval: 10,
                min: <?php echo $ymin; ?>,
                max: <?php echo $ymax; ?>,
            },
        },

    });

how would I be able to rerender the graph wihtout a page refresh, considering that I also need to run some php to determin my json data using php?

考虑到我还需要运行一些php来使用php确定我的json数据,我怎么能够在页面刷新时重新渲染图形?

thanks!

2 个解决方案

#1


0

Its pretty simple dynamically refreshing the data returned from an ajax call.

它非常简单,动态刷新从ajax调用返回的数据。

So, first of all you would need to use an AJAX call that will return you the data required by the chart in the desired format.

因此,首先您需要使用AJAX调用,该调用将以所需格式返回图表所需的数据。

Next, once the data has been returned from the AJAX request, you have to simply first empty the div using jQuery like $('#chartdiv').empty(); and then simply rerun your code to replot the graph using the new data.

接下来,一旦从AJAX请求返回数据,您必须首先使用jQuery清空div,如$('#chartdiv')。empty();然后只需重新运行代码即可使用新数据重新绘制图形。

Also, as you want to make use of the previous data used for drawing the chart, you can simply store the same json data in a javascript variable and then modify the same variable accordingly based on the data received from the ajax request.

此外,由于您想要使用以前用于绘制图表的数据,您可以简单地将相同的json数据存储在javascript变量中,然后根据从ajax请求接收的数据相应地修改相同的变量。

You can also, make use of the jqgrid functions like plot.destroy(); plot.replot();

您还可以使用plot.destroy()等jqgrid函数; plot.replot();

更多相关文章

  1. 加载函数加载页面但不能对数据执行任何操作
  2. jQuery $ajax 传中文数据到action乱码解决方法
  3. 导入地址簿联系人,存储在数组中并保存到数据库
  4. Twitter在模式窗口中引导数据表程序
  5. jquery mobile界面数据刷新
  6. 将数据从jQuery Ajax发送到MVC COntroller
  7. jQuery无法从localhost检索数据
  8. 如何使用jquery ajax获取api数据?
  9. 将css添加到jquery数据表中的特定单元格

随机推荐

  1. 入职以来,我和老大之间的故事。
  2. 请不要拒绝成熟!
  3. C语言函数以及函数的使用
  4. android 界面中加入密码框
  5. android Theme启动APP闪屏处理
  6. Android给TextView添加点击事件的实现方
  7. android跑马灯有时候不跑
  8. android 的常标签和方法 android 初学者
  9. android支付宝首页、蚂蚁森林效果、视频
  10. Android 实现显示文字的Gallery