Thanks, Massimo! I've said it before, but it's certainly worth repeating. You are running the most responsive and helpful group on the web.
So I've almost got it working with your suggestion, but I'm running into what seems to be an issue with javascript's scoping rules. My service function is definitely being called once per second, but nothing gets drawn unless I put both the 'b' array and the call to $ (this).sparkline(b) outside the getJSON() call, but then 'b' is not changed outside the getJSON() call. OTOH if I put the sparkline() call inside the function(data) block, then it looks like $(this) is no longer referring to the DIV element with class 'dynamicsparkline'. I'm sure there's a way to sort it out. I think it's just that js is so fugly compared to python that I have a hard time forcing myself to really learn it. Cheers, Mike On May 14, 7:53 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > Try this: replace > > $(function() { > $('.dynamicsparkline').everyTime(1000,function(i) { > var a = [10,9,8,7,6,5,4]; > var b = [0,0,0,0,0,0,0] > var j = 2+i%5; > for(var k=0; k<b.length; k++) { b[k] = a[k] > %j;} > $(this).sparkline(b); > }); > }); > > with > > $(function() { > $('.dynamicsparkline').everyTime(1000,function(i) { > $.getJSON('{{=URL(r=request,f='call/json/ > datapoints')}}/'+i, function(data) { > var b = [0,0,0,0,0,0,0] > var j = 2+i%5; > for(var k=0; k<b.length; k++) { b[k] = data.a[k] > %j;} > $(this).sparkline(b); > }); > }); > }); > > AND > > @service.jsonrpc ## or is xmlrpc easier? > def datapoints(j): > return [n%j for n in [10,9,8,7,6,5,4]] > > WITH > > @service.json > def datapoints(j): > return dict(a=[10,9,8,7,6,5,4]) > > On May 14, 3:32 pm, MikeEllis <michael.f.el...@gmail.com> wrote: > > > Hi, > > I'm trying to create an application that displays live sparklines > > (small inline graphs). A typical page might have a dozen or so of > > these updating every few seconds, so it seems like either jsonrpc or > > xlmrpc is the right thing to use. > > > As a test, I've currently got sparklines updating on the client side > > using the jquery.sparkline and jquery.timers plugins. The code to > > make it work is pretty straightforward. After including the > > aforementioned plugins at the top of web2py_ajax.html, I can create a > > sparkline that updates once a second with code at the bottom of > > web2py_ajax.html like the following: > > > <script type="text/javascript"> > > /* <![CDATA[ */ > > $(function() { > > > $('.dynamicsparkline').everyTime(1000,function(i) { > > var a = [10,9,8,7,6,5,4]; > > var b = [0,0,0,0,0,0,0] > > var j = 2+i%5; > > for(var k=0; k<b.length; k++) { b[k] = a[k] > > %j;} > > $(this).sparkline(b); > > }); > > }); > > /* ]]> */ > > </script> > > > and in my view the following code: > > > <p> > > Sparkline with dynamic data: <span class="dynamicsparkline">Loading..</ > > span> > > </p> > > > displays a nice little wiggly graph that changes once a second. Just > > the effect I'm looking for. > > > So my question is this: What's the most straightforward way to > > rewrite this trivial little demo so the data calculation takes place > > server side? Clearly the work would be done by a function that looks > > something like the following: > > > @service.jsonrpc ## or is xmlrpc easier? > > def datapoints(j): > > return [n%j for n in [10,9,8,7,6,5,4]] > > > but what plugins, initializations and function calls are needed > > client-side to replace the lines in my javascript example that fill > > the 'b' array with the values to be plotted? > > > Thanks, > > Mike > >