Flotr.draw in a loop

43 views
Skip to first unread message

Mike B

unread,
Aug 24, 2010, 10:20:24 PM8/24/10
to Flotr Javascript Plotting Library
Hello,

I have some charts that grab data from a database that is updating
every 30 sec. I'd like to be able to redraw the charts every minute
without reloading the page.

So, is there a way to put this:

Flotr.draw(
$('flotr_obj_'+c+'_int'),
alld,
options
);

...into a loop? I've tried setTimeout and setInterval but that 'c'
variable always comes through as undefined.

Better yet, is there (or are there plans for) some sort of chart
refresh interval?

Thanks!

George Roberts

unread,
Aug 25, 2010, 12:45:10 AM8/25/10
to fl...@googlegroups.com
Why do you want to change the object you draw into with the variable c?

A simpler method would be to just redirect back to the same page every 30
seconds, say with this:
location.href=mypage.htm

A nicer method that doesn't waste as much internet traffic and server usage
would be to grab a json packet of data every 30 seconds and then redraw the
graph from scratch. Into the same div! Don't make a new div every time
with this weird c variable.

I have code that redraws flotr graphs 10 times per second. It works fine -
flotr is pretty fast even on slow machines.

- George Roberts
http://gr5.org

--------------------------------------------------
From: "Mike B" <mbbo...@gmail.com>
Sent: Tuesday, August 24, 2010 10:20 PM
To: "Flotr Javascript Plotting Library" <fl...@googlegroups.com>
Subject: Flotr.draw in a loop

> --
> You received this message because you are subscribed to the Google Groups
> "Flotr Javascript Plotting Library" group.
> To post to this group, send email to fl...@googlegroups.com.
> To unsubscribe from this group, send email to
> flotr+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/flotr?hl=en.
>
>

Joel Oughton

unread,
Aug 25, 2010, 12:48:42 AM8/25/10
to fl...@googlegroups.com
The following code uses setInterval and works fine...

You must have got confused with the scope of your "c" variable.

        <div id="flotr_obj_chart1_int" style="width:600px;height:300px;"></div>
       
        <script type="text/javascript">

            document.observe('dom:loaded', function(){
                var c = "chart1";
               
                foo();

                function foo() {
     
                  var interval = 500; // in ms
                  d1 = [[0, 3], [4, 8], [8, 5], [9, 13]];
                 
                  setInterval(function() {
                    Flotr.draw( $('flotr_obj_'+ c +'_int'), [ d1 ]);
                 }, interval);
                }
            });           
        </script>
Reply all
Reply to author
Forward
0 new messages