Page 1 of 3

Loading data into jqplot from database

Posted: Mon Jul 07, 2014 8:11 am
by Peter Castle

Hello Appery.io & Community,

I am trying to populate a jqplot in my app using data from my database. The database has several sensor temperature readings over time. Therefore the idea is to create a graph with say 8 lines (from 8 sensors) each with it's own sensor ID stored in a common database collection. Each line would consist of say the most recent 10 temperature readings.

I have been able to create a jqplot successfully with dummy data as per other threads.

I have been able to produce a database query service to gather the data, but am not sure how to store this data in an array (or several arrays - maybe one per sensor) so that they can be loaded into jqplot (as above?).

Can someone advise exactly how to use "Local storage variables" (assuming this is the best way) to hold arrays of data retrieved from a database collection and then use them for a jqplot?


Loading data into jqplot from database

Posted: Mon Jul 07, 2014 8:13 am
by Peter Castle

// FORMAT LOCAL VARIABLE DATA INTO JQPLOT FORMAT

var L1 = localStorage.getItem("D1");
var line1 = [];
for (var i=0; i
}
}
}
);


Loading data into jqplot from database

Posted: Mon Jul 07, 2014 8:14 am
by Peter Castle

FYI - the sensor readings are a NUMBER data type.


Loading data into jqplot from database

Posted: Mon Jul 07, 2014 9:57 am
by Kateryna Grynko

Hi Peter,

localStorage stores data as strings. You can convert a string to an array:prevar arr = JSON.parse(localStorage.getItem("variableName"));/pre


Loading data into jqplot from database

Posted: Mon Jul 07, 2014 10:17 am
by Peter Castle

Ok, so Local storage variables are the best way to go here?

I also have noticed the following code on a tutorial, is this how to store a NUMBER?

var response = JSON.stringify(data);
localStorage.setItem("json_response", response);

But how can I get the data (multiple sensor readings per sensor) into the local storage?

Image


Loading data into jqplot from database

Posted: Mon Jul 07, 2014 10:18 am
by Peter Castle

Do I have to add java script to the D1 - D4 local storage variables?


Loading data into jqplot from database

Posted: Mon Jul 07, 2014 10:21 am
by Peter Castle

Loading data into jqplot from database

Posted: Mon Jul 07, 2014 10:22 am
by Peter Castle

Loading data into jqplot from database

Posted: Mon Jul 07, 2014 10:27 am
by Peter Castle

Here is some simple dummy data in my collection. As you can see, there are two NodeUnitID's (121 & 123), each with 6 data points for 4 sensors each.

Therefore the arrays needing to be stored locally would be:
sensor1 = [1, 2, 3, 4, 5, 6];
sensor2 = [1, 2, 2, 3, 4, 5];
.
.
.
sensor7 = [1, 2, 2, 2, 3, 2];
sensor8 = [1, 1, 2, 2, 1, 1];

How do I store these arrays?


Loading data into jqplot from database

Posted: Mon Jul 07, 2014 1:01 pm
by Kateryna Grynko

Hi Peter,

Why don't you store records D1..D10 in one Database field of Array type? It would be easier to retrieve values...