Peter Castle
Posts: 0
Joined: Mon Jul 07, 2014 8:11 am

Loading data into jqplot from database

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?

Peter Castle
Posts: 0
Joined: Mon Jul 07, 2014 8:11 am

Loading data into jqplot from database

// FORMAT LOCAL VARIABLE DATA INTO JQPLOT FORMAT

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

Peter Castle
Posts: 0
Joined: Mon Jul 07, 2014 8:11 am

Loading data into jqplot from database

FYI - the sensor readings are a NUMBER data type.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Loading data into jqplot from database

Hi Peter,

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

Peter Castle
Posts: 0
Joined: Mon Jul 07, 2014 8:11 am

Loading data into jqplot from database

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

Peter Castle
Posts: 0
Joined: Mon Jul 07, 2014 8:11 am

Loading data into jqplot from database

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

Peter Castle
Posts: 0
Joined: Mon Jul 07, 2014 8:11 am

Loading data into jqplot from database

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?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Loading data into jqplot from database

Hi Peter,

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

Return to “Issues”