d3.js - How to generate graphs and charts on the fly using web2py -


i getting data after firing databases. want generate basic graphs using data interpret results. read posts protovis helpful in achieving can't find content it. in ideal scenario use d3js generated data driven documents.

here example of how use d3.js in web2py. works me using this d3.js sample book, interactive data visualizations web.

add controller, controllers/d3js.py

import random  def histogram():     dataset = [(random.randint(1,6) + random.randint(1,6)) in range(100)]     return dict(dataset=dataset, title='d3.js histogram') 

add view view/d3js/histogram.html contains d3.js code utilising dynamic features passed controller.

<!doctype html> <html lang="en">     <head>         <meta charset="utf-8">         <title>{{=title}}</title>         <script type="text/javascript" src="https://d3js.org/d3.v3.min.js" ></script>     </head>     <body>         <script type="text/javascript">              {{from gluon.serializers import json}}             var dataset = {{=xml(json(dataset))}};              //width , height             var w = 600;             var h = 600;             ...              //create svg element             var svg = d3.select("body")                         .append("svg")                         .attr("width", w)                         .attr("height", h);              ...          </script>     </body> </html> 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -