views:

41

answers:

1
var options = {
    series: {lines: {fill: true, fillColor: "rgba(255, 255, 204, 0.5)"} },
    xaxis: { mode: "time", timeformat: "%d %b %y", minTickSize: [1, "month"]}    ,
    yaxis: { max: 50000}
};
var d3;
var plot;
$(document).ready(function(){
    d3 = <?echo $balarray;?>;
    plot = $.plot($("#placeholder"), [d3],options );
    $("#calInput1").blur(function(event){
        $(this).clear();
    });
    $('#show').click(function(){
        $.post("/sandbox/graphloader",{calInput1:$('#calInput1').val(), calInput2:$('#calInput2').val()} ,function(data) {

            plot.setData(data);
            plot.draw();
        });
    });
}); 

I am trying to do ajax call to a kohana controller with this. I want to redraw it on click of a button. why isn't the redraw working ?? (At load it is showing the graph fine)

A: 

You probably need to deserialize the string (data), jquery/javascript does not make assumption about the type of data returned by the ajax result.

dvhh
I am definitely sending a string from my server, a php echo does it... I'll try deserialization on the data and let you know...
Shrinath
btw, is the implementation correct ?? about the plot.draw and all ??
Shrinath
well not knowing what your data look like I guess that according to the api the usage seems ok (for the flot part anyway).
dvhh
my data if I "alert(data)" prints a box with [[2010-05-01,234.4],[2010-05-02,333.3]] and so on...
Shrinath
then you should write some custom parser for your data as the date string is not quoted for using eval (which you shouldn't use anyway), or modifify your server script to serialize the data in a way that javascript wouuld more easily understand
dvhh
well, how is it understanding in the first load then ??
Shrinath
can I have some demo page? it is probably understanding it in a wrong way example: eval([[2010-05-01,234.4],[2010-05-02,333.3]]) => [[2004, 234.4], [2003, 333.3]], so of course xxxx-xx-xx is a valid javascript expression but because it is performing substractions
dvhh
The page is not up yet, I'll try and setup one... Coming back to the problem atleast I should see the same in "alert" too right ?? I am seeing the right data in alert.. ?
Shrinath
anyway, how do you prevent javascript from doing eval on my data ?? :)
Shrinath
alert is showing the string, and not the actual array data that you want
dvhh
setData works with array, you should probably do an alert(d3); before plotting it
dvhh
You should certainly have to quote the date data like [["2010-05-01",234.4],["2010-05-02",333.3]] in your php
dvhh
I did that quote job in php, thats there...
Shrinath
ok, I figured a way... I did this : var obj=eval(data); works now :) thanks dude :) got that somewhere in stackoverflow itself :)
Shrinath