-
• #2
- Cursors? (for a given X value / for a MAX or MIN value , ...)
- Automatic X scrolling (when defining a window width)?
- Gauge?
Nice work, by the way !
- Cursors? (for a given X value / for a MAX or MIN value , ...)
-
• #3
What about grid with dots in the graph section
1 Attachment
-
• #4
min/max/ave
-for graph on display
-for total measurement (history module) -
• #5
Thanks for the suggestions!
Having the ability to mark a point and display its value would be great, and as you say @Jean-Philippe_Rey being able to move it around to find a value would be really handy.
Gauges would be good too - but probably best for another module?
I'm not convinced that a grid would be that useful on the Pixl display - on something with grayscale it'd be really good though.
@Spocki do you have an example of how you'd want those things shown on the graph? Having stats in the history module would be extremely handy though as you say.
-
• #6
I am trying to get the graph to work with realtime data using the tinydash widget. The graph in the example file works but it is just plotting a curve on start without any updates. Whenever I try to push live sensor values to the graph I get no line being drawn. Is it possible to get an example of the tinydash graph widget that updates with new incoming values. Thanks
-
• #7
Sure - I think the RSSI grapher in EspruinoHub does it: https://github.com/espruino/EspruinoHub/blob/master/www/rssi.html#L106
You just need to call
setData
on the graph itself -
• #8
You beat me to it. I was excited because a friend already pointed me in the right direction and I got it working earlier today. Thanks for the quick response and I still am looking forward to looking over the example you shared. Here is the code I used
<html> <head> <meta name="viewport" content="width=640, initial-scale=1"> </head> <body> <link href="/static/css/tinydash.css" rel="stylesheet"> <script src="/static/tinydash.js"></script> <script src="/static/puck.js"></script> <script> var t; var j_light; t = []; function onLine(line) { try { var j = JSON.parse(line); console.log("Received JSON: ",j); j_light = j.light*100; t.push(j_light); elements.light.setValue(j_light); elements.logg.log(j_light); elements.gr.setData(t); } catch(e) { console.log("Received: ",line); } } var connection; function connectDevice() { Puck.connect(function(c) { if (!c) { alert("Couldn't connect!"); return; } connection = c; // remove modal window elements.modal.remove(); // Handle the data we get back, and call 'onLine' // whenever we get a line var buf = ""; connection.on("data", function(d) { elements.log.log(40*Math.sin(Date.now()/1000)+50); //elements.logg.log(connection.write("digitalRead(BTN);\n")); buf += d; var i = buf.indexOf("\n"); while (i>=0) { onLine(buf.substr(0,i)); buf = buf.substr(i+1); i = buf.indexOf("\n"); } }); // First, reset Puck.js connection.write("reset();\n", function() { // Wait for it to reset itself setTimeout(function() { // Now tell it to write data on the current light level to Bluetooth // 10 times a second. Also ensure that when disconnected, Puck.js // resets so the setInterval doesn't keep draining battery. //TD.update({log : 40*Math.sin(Date.now()/1000)+50}); connection.write("setInterval(function(){Bluetooth.println(JSON.stringify({light:Puck.light()}));},100);NRF.on('disconnect', function() {reset()});\n", function() { console.log("Ready..."); }); }, 1500); }); }); } //function getTempValue() { // for (var i=0;i<100;i++) t.push(i); //connection.write("Puck.temp();\n", function(temper){ //for (var i=0; i<100;i++) t.push(temper); // {elements.gr.setData(t);} // setTimeout(function() { // getTempValue(); // }, 250); // }); // } // Set up the controls we see on the screen var elements = { heading : TD.label({x:10,y:10,width:200,height:50,label:"My Dashboard"}), b:TD.button({x:10,y:290,width:200,height:100,label:"Press Me",value:0,name:"button",onchange:function(e){elements.log.log("Pressed!");}}), log:TD.log({x:430,y:10,width:190,height:200,label:"A Log",text:"A\nB\nC"}), logg:TD.log({x:630,y:10,width:190,height:200,label:"A Log",text:"A\nB\nC"}), //function() { // connection.write("Puck.getBatteryPercentage();\n"); //elements.logg.log(connection.write("Puck.getBatteryPercentage();\n")); //Puck.eval("{bat:Puck.getBatteryPercentage()}" // }}), light : TD.gauge({x:10,y:70,width:200,height:220,label:"Light",value:0,min:0,max:100}), redled : TD.toggle({x:210,y:200,width:200,height:90,label:"Red LED",value:0,onchange:function(el,v) { connection.write("LED1.write("+v+");\n"); }}), flash : TD.button({x:420,y:200,width:190,height:90,label:"Flash!",value:0,onchange:function() { connection.write("digitalPulse(LED3, 1, 500);\n"); }}), vs:TD.value({x:10,y:400,width:200,height:60,label:"Steppable Value",value:"1.2",min:1,step:0.1,max:2}), // gr:TD.graph({x:220,y:420,width:400,height:170,label:"A Graph",data:function(){ // connection.write("Puck.temp();\n");}}), gr:TD.graph({x:220,y:420,width:400,height:170,label:"A Graph",data:t}), modal: TD.modal({x:10,y:10,width:190,height:430,label:"Click to connect",onchange:connectDevice}) } elements.log.log("Hello"); for (var i in elements) document.body.appendChild(elements[i]); </script> </body> </html>
-
• #9
Great! Thanks for posting up your finished code too - that should really help others :)
Hi,
I started work on a library to make graphing a bit easier. The code below runs on a Pixl.js, or any other device as long as you create a Graphics instance called
g
.Currently it does:
What kind of functionality is needed to you think? Bearing in mind the display is quite low-res...
Thoughts so far:
another module to handle keeping track of a 'history' array
1 Attachment