Greetings,
Im using web2py to store data in an IOT project, saving data works
perfectly but i want to create some graphs to show stats or summary using
highcharts/highstock
*line chart.*
Thats the code and the output
CONTROLLER
@auth.requires_login()
@service.json
def mystats():
ownstats = db(db.water_flow_log.meter ==
auth.user.username).select(db.water_flow_log.ALL,orderby=~db.water_flow_log.date_made)
rows = db(db.water_flow_log.meter ==
auth.user.username).select(db.water_flow_log.ALL,orderby=~db.water_flow_log.date_made)
return response.json([[r.created_on, r.qty] for r in rows])
VIEW
{{extend 'layout.html'}}
<html>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<div id="chart"></div>
<script type="application/javascript">
$.getJSON('http://127.0.0.1:8000/Meter/default/call/json/mystats',
function (data) {
// pie subscription
$('#pie_subscription').highcharts({
series: [{
type: 'line',
name: '{{=T('Subscription') }} ',
data: [
{{for row_pie_subscription in rows:}}
['{{=T(row_pie_subscription.created_on) }}',
{{=row_pie_subscription.qty}} ],
{{pass}}
]
}],
});
});
</script>
</html>
OUTPUT
[["2017-02-24 14:32:20", 275.0], ["2017-02-24 10:52:50", 272.0], ["2017-02-24
10:32:57", 270.0]]
--
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.