I ended up using pygal it looks more open on data organization and it
doesnt even require json format
def mystat():
response.files.append(URL('default', 'static/js/pygal-tooltips.min.js'))
response.headers['Content-Type'] = 'image/svg+xml'
import pygal
from pygal.style import CleanStyle
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)
quants = db(db.water_flow_log.meter ==
auth.user.username).select(db.water_flow_log.ALL,orderby=~db.water_flow_log.date_made)
all_data= response.json([[r.created_on, r.qty] for r in rows])
all_qty = [q.qty for q in quants]
all_dates = [q.created_on for c in quants]
graph = pygal.StackedLine(fill=True)
graph.title = '% Water Consumption.'
graph.x_labels = all_dates
graph.add('Water in ML', all_qty)
print all_qty
print all_dates
return graph.render()
On Thursday, March 2, 2017 at 12:50:31 PM UTC+2, Marlysson Silva wrote:
>
> Are you done?
>
> Em terça-feira, 28 de fevereiro de 2017 20:01:57 UTC-3, Oasis Agano
> escreveu:
>>
>> 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.