Highcharts in web2py

222 views
Skip to first unread message

kecajk...@gmail.com

unread,
May 11, 2016, 9:15:38 AM5/11/16
to web2py-users
Hi Guys, 

I was able to create simple graph by using highcharts.js  (http://www.highcharts.com/)  However since it's javascript it's really hard to add some data from controller. I found python module for highcharts:



Anybody has an experience or idea how to create chart using it and how to display it in the view? 

Cheers.

Paolo Amboni

unread,
May 11, 2016, 9:41:21 AM5/11/16
to web2py-users
why did you choose Highcharts?
I'm still searching the right  library for web2py!!

Carlos Cesar Caballero Díaz

unread,
May 11, 2016, 9:51:58 AM5/11/16
to web...@googlegroups.com
Hi, is really easy integrate technologies like Highcharts in a web2py site using JSON, XML or CSV, here you can find how fill a chart from JSON, XML or CSV (http://www.highcharts.com/docs/working-with-data/data-intro) and you can look at the web2py book for JSON, XML or CSV data rendering (http://www.web2py.com/books/default/chapter/29/10/services#HTML-XML-and-JSON and http://www.web2py.com/books/default/chapter/29/10/services#CSV).

Greetings.

El 11/05/16 a las 09:15, kecajk...@gmail.com escribió:
--
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

José Luis Redrejo

unread,
May 12, 2016, 2:07:33 AM5/12/16
to web...@googlegroups.com
I've played with highcharts and it's pretty simple if you use the json decorator in web2py.
On the other hand, if you want a really free library I'd recommend you to use d3js. The examples in its site are really good and you only need to replace d3.tsv.... by d3.json(... calling the controller and format your data in the controller to return the data in the same format that the tsv file from the example to make them work.
Highcharts is a bit easier than d3js, but it's less flexible and you have to pay a license to use it in a commercial application, while d3js is totally free.

My 20 cents.
José L.

Alfonso Serra

unread,
May 12, 2016, 12:24:06 PM5/12/16
to web...@googlegroups.com
Actually is quite easy.

Prepare some data on your controller:
import json

def index():
   
...
   
#get some rows from any source

   countries
= XML(json.dumps([[r.country_name, r.population] for r in rows]))

At your view:
//declare the libraries here, jquery hc, etc
....
<script type="text/javascript">
(function ()
var mychart = $("#mychart").highcharts({
...set some options

...feed the data to the chart
 
, series: [{
name
: "anyname"
data
: {{=countries}}
}]
   
}
})();

or

, series: {{=str(anyarray_from_the_controller)}}


  

Reply all
Reply to author
Forward
0 new messages