简体   繁体   English

无法正确更新ajax响应上的Flot图

[英]Unable to properly update Flot graph on ajax response

I have a graph that is properly generated when the page loads. 我有一个在页面加载时正确生成的图表。 That code is: 该代码是:

<body>
<div id="placeholder" style="width:800px;height:400px;"></div>

<script type="text/javascript">
$(function () {
    $.plot($("#placeholder"),
[ { data: %s } ],
{ xaxes: [ { mode: 'time' } ],
  yaxes: [  ] })
});
</script>

Which works fine. 哪个工作正常。 I have a button that executes jquery and makes a request to get a new json data structure. 我有一个执行jquery的按钮,并请求获取一个新的json数据结构。 I've validated that the json being returned is indeed proper json. 我已经验证了返回的json确实是正确的json。 I'm attempting to graph the result with: 我试图用以下结果绘制结果:

<script type="text/javascript">
$(function() {
      $("#button").click( function()
           {
             //alert('button clicked');
             $.ajax({
                url:  '/graph',
                type: 'POST', 
                dataType: 'html',
                data: {
                    start_date: $('#start_date').val(),
                    end_date  : $('#end_date').val(),
                    ticker    : $('#ticker').val()
                },
                success: function(result) {
                var placeholder = $("#placeholder");
                $.plot(placeholder,
                  [ { data: result } ], 
                    { xaxes: [ { mode: 'time' } ],
                      yaxes: [  ] });  
             }
            });
          }
      );
});

Which redraws the graph, but it's empty and the y-axes is the default -1.0 through 1.0 and the x-axes is a single time entry of 00:00:00. 哪个重绘了图形,但是它是空的,y轴是默认的-1.0到1.0,x轴是00:00:00的单个时间条目。

I've tried to use the setData() and draw() method calls but they don't fix the issue. 我曾尝试使用setData()和draw()方法调用,但它们无法解决问题。

There are no javascript errors being thrown as shown by firebug. 如firebug所示,没有抛出javascript错误。 So, what am I doing wrong? 那么,我做错了什么?

TIA! TIA!

Are you sure the response is valid? 您确定回复有效吗? Your dataType is 'html', so unless you're doing something with a script tag, then the response is just a string. 您的dataType是'html',因此除非您使用脚本标记执行某些操作,否则响应只是一个字符串。 If you're returning JSON directly, then you need to use dataType 'json'. 如果您直接返回JSON,则需要使用dataType'json'。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM