Show us how are your data returned by your query..

Em quarta-feira, 1 de março de 2017 05:48:51 UTC-3, Oasis Agano escreveu:
>
> Thank you for the reply but when i do this i get a serialization error on 
> datetime, plus i think my problem is on the view not the controller.
> kr
> oasis
>
> On Wednesday, March 1, 2017 at 1:17:42 AM UTC+2, Marlysson Silva wrote:
>>
>> In your controller try to use the simplejson from gluon intead json dumps 
>> from python and return the lists formatted to your chart.
>>
>> 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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to