Do you actually have those javascripts installed? It seems to work with the CDN versions
#!/usr/bin/env perl
use Mojolicious::Lite;
any '/' => 'index';
websocket '/data' => sub {
my $self = shift;
my $timer = Mojo::IOLoop->recurring( 1 => sub {
state $i = 0;
$self->send({ json => gen_data($i++) });
});
$self->on( finish => sub {
Mojo::IOLoop->remove($timer);
});
};
sub gen_data {
my $x = shift;
return [ $x, sin( $x + 2*rand() - 2*rand() ) ]
}
app->start;
__DATA__
@@ index.html.ep
% layout 'basic';
%= javascript 'https://code.jquery.com/jquery-2.1.4.min.js';
%= javascript 'https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquer
+y.flot.js'
<div id="plot" style="width:600px;height:300px">
</div>
%= javascript begin
var data = [];
var plot = $.plot($('#plot'), [ data ]);
var url = '<%= url_for('data')->to_abs %>';
var ws = new WebSocket( url );
ws.onmessage = function(e){
var point = JSON.parse(e.data);
data.push(point);
plot.setData([data]);
plot.setupGrid();
plot.draw();
};
% end
Shell:
:~$ morbo t1.pl
Server available at http://127.0.0.1:3000
[Wed Jun 17 21:54:11 2015] [debug] Your secret passphrase needs to be
+changed
[Wed Jun 17 21:54:11 2015] [debug] GET "/"
[Wed Jun 17 21:54:11 2015] [debug] Rendering template "index.html.ep"
+from DATA section
[Wed Jun 17 21:54:11 2015] [debug] Template "layouts/basic.html.ep" no
+t found
[Wed Jun 17 21:54:11 2015] [debug] 200 OK (0.005384s, 185.736/s)
[Wed Jun 17 21:54:11 2015] [debug] GET "/data"
[Wed Jun 17 21:54:11 2015] [debug] Routing to a callback
[Wed Jun 17 21:54:11 2015] [debug] 101 Switching Protocols (0.000710s,
+ 1408.451/s)
Browser shows oscillating lines and scaling horizontal axis. Where did you get this example from?