Hi Anthony,
I have successfully get the values from another file... thanks...
But for now i have another problem displaying the values into a graph...
In views/default/index.html
{{extend 'layout.html'}}
{{=LOAD('default', 'graph', ajax=True, timeout=500, times='infinity')}}
{{=BEAUTIFY(response._vars)}}
In my default.py controller
from gluon.serializers import json
def index():
return dict()
def graph():
temp_graph = []
temp=[]
timet=[]
for x in db().select(db.temperature_table.ALL):
temp.append(x.temp_value)
timet.append(x.tm_timestamp)
temp_graph.append({'y':x.temp_value, 'label':x.tm_timestamp})
return dict(temp_graph=json(temp_graph),VA=temp,VB=timet)
In views/default/graph.html
<script src="{{=URL('static','js/canvasjs.min.js')}}"></script>
<div id="chartContainer" style="height: 300px; width: 50%;"></div>
{{=VA}}
{{=VB}}
<br> ------------ Value In Graph ------------ <br>
{{=temp_graph}}
<script type="text/javascript">
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
theme: "theme3",
legend: {
horizontalAlign: "center", // "left" , "right"
verticalAlign: "bottom", // "center" , "top"
fontSize: 12
},
title:{
text: "Temperature reader"
},
animationEnabled: false,
data: [
{
type: "line",
showInLegend: true,
legendText: "temperature",
dataPoints: {{=XML(temp_graph)}}
}
]
});
chart.render();
}
</script>
In Browser the <graph.html> renders the graph and value completely with no
problems
But the in <index.html> the graph does not render.. only Values are shown..
I have also tried increasing the value of the timeout maybe the graph is
not rendered due to timeout value but still no avail...
{{extend 'layout.html'}}
{{=LOAD('default', 'graph', ajax=True, timeout=20000, times='infinity')}}
{{=BEAUTIFY(response._vars)}}
On Friday, September 8, 2017 at 7:06:32 PM UTC+8, Anthony wrote:
>
> What does your newvalue.load view look like? Does it display the temp and
> timet lists?
>
> Note, your index.html view is incorrect -- it has {{=temp}} and
> {{=timet}}, but the dictionary returned by the index() function instead
> uses VA and VB as keys, so the view should have {{=VA}} and {{=VB}} (should
> be the same in your newvalue.load view). Actually, because the returned
> values are Python lists, you probably want a more sophisticated display
> than simply {{=VA}}.
>
> Also, note that there is no reason to have two identical functions. You
> can instead have a single function and just use two different views and
> extensions (i.e., index.html and index.load).
>
> Even better, just use an Ajax component to load the data and set it to
> refresh periodically:
>
> def index():
> return dict()
>
> def get_data():
> ...
> return dict(VA=temp, VB=timet)
>
> In views/default/index.html:
>
> {{=LOAD('default', 'get_data.load', ajax=True, timeout=1000, times=
> 'infinity')}}
>
> In views/default/get_data.load:
>
> {{=VA}}
> {{=VB}}
>
> Keep in mind that this is an inefficient way to get realtime updates.
> First, you are polling every second, whether or not the data have changed.
> Second, you are sending all the data on every request instead of just the
> changes. This may be fine for your use case, but a more efficient approach
> would be to use a server push pubsub method (e.g., use websockets to
> publish updates to the client) -- see
> https://github.com/web2py/web2py/blob/master/gluon/contrib/websocket_messaging.py
> .
>
> Anthony
>
>
> On Friday, September 8, 2017 at 2:52:57 AM UTC-4, Wabbajack wrote:
>>
>> Hi All,
>>
>>
>>
>> I am really confused on auto updating variable on view...
>> What i want is i have an initial value that is displayed on
>> index.html<view> thru query in default.py index function
>> But hope to change this values everytime there is a change on the
>> database.
>>
>> I have read this
>> https://groups.google.com/forum/#!topic/web2py/XN9Wqb3jqKk
>> but still having confusion the variable arent updating or creating new
>> string file
>>
>>
>> *controllers/default.py
>>
>>
>> *view/default/index.html
>>
>>
>>
>> * Also i have created a file newvalue.load on views/default/ directory
>>
>>
>> *models.py
>>
>>
>> <additional info>
>> I am using web2py 2.14 on windows PC
>>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.