Hi,
I spent some time working on it, although it's still a work in progress.
So far I've managed to read a CSV file using javascript and save it to a 2-dimension array. Then, I created a function to substract a number of milliseconds from the first column (the date) in order to get the previous day/week/month,etc. After that, I insert a new row containing the new date and its associated value in another column.
At this point, you have a bunch of rows containing dates and values (some at the 2nd row, some at the 3rd) with some empty values in between (you have to make sure these are blank). But dygraph needs to process the data in chronological order, so the next step is to sort all those dates.
Once they are in ascending order, you need to tell dygraph to connect all the datapoints regardless of the presence of empty datapoints in between.
I have assigned a button to call the functions that carry out all these processes, so every time I click the button, another column is added to the array and displayed as a series in the graph.
Right now it kinda works, but I have to optimize it. If the original CSV contains several tens of thousands of rows it can take a few seconds until the "previous" series is generated. And if called several times (which there's no need to), the array could grow exponentially and freeze your browser. Right now I wouldn't recommend it if you have less than 6GB of RAM ;) I've been thinking of only processing the range of data which is currently being displayed on the graph. Also, on CSV with multiple data series, I still have to tell the script which series should it use and where to place the new columns manually.
About the server, I'm using a Raspberry pi model B (1st gen) running raspbian stretch with the nginx web server and php7. I think it's better to compute the data on the client's side, since the device on which the browser will be run will almost sure be more powerfull than the raspberry's CPU, even if it means a little delay until the graph is displayed. Alternatively, I could use a mixed approach: generate the time series dynamically with the raspberry pi and displaying the graph using dygraph. If I use the raspberry to generate the data files and the graphs (using gnuplot), the CPU is in use almost all the time (since there are quite a lot of sensors and data files that i'm processing...) and I can't use for anything else.
Anyway, you can close the thread if you want. I've more or less managed to do what I intented and I only need to optimize it now. I can share the code if you want, but right now it's a mess, since it's the first time i used javascript and I'm no programmer at all, just a hobbyist.
Thank you for your help, and I hope it can be useful to somebody in the future
Best regards,
Marc
El dissabte, 23 desembre de 2017 17:00:23 UTC+1, István Bánhidi va escriure: