SlideShare uma empresa Scribd logo
1 de 7
FusionChart Django Wrapper
Definition:
Python 2.7 provides some interesting concepts like decorators or wrappers. The function
decorators or wrappers change the action of the original function before or after the execution of
the function. In this type of case the original function does not modify itself but the working is
decorated by the wrapper according to its principal. The easiest example is wrapping a function
return by some html/JavaScript tags. If a function returns some name as output, the decorator can
modify it using the <p>, <b>, <i> tags etc.
Example::
Input:
def get_result(intro):
return “Captain America, {0} in civil war” .format (intro)
def pb_ decorate (func):
def func_wrap(intro):
return “ <p><b>{0}</p></b>” .format (func(intro))
return func_wrap
mah_movie= pb_decorate ( get_result)
print mah_movie ( “Chris Evans”)
Output:
<p><b> Captain America, Chris Evans in civil war</b></p>
However, calling the decorating function has a clear shortcut. This kind of function can be
identified prepending ‘@’ in it. In the above example the decorator should be @pb_decorate ().
Django wrapper:
This special type of decorator or wrapper provides the advantage of class based views over the
function based views. The wrapper organizes server side HTTP methods like Get, Post etc using
separate methods instead of branching ( if/else / for/ while). The wrapper also provides object
oriented process like ‘mixins’, ‘prefork working module’ etc. The wrapper uses toolkit and
multiple inheritance (‘mixins’) to increase the extensibility and flexibility of the class based
attributes.
CODE:
from django.http import HttpResponse
from django.views.generic import View
class GreetView(View):
greeting = "Nice Day"
def get(self, request):
return HttpResponse ( self.greeting )
In the above code The URL resolver of the Django wrapper expects the arguments from a
function and not a class therefore the view method serves as the opening point of the class. The
view method creates an interface for dispatch () method to identify the type of request
(Get/Post/not allowed response) and works according to it.
Purpose of the Wrapper:
The python module (wrapper) creates an interface between python and a third party library. The
advantage of this kind of module is the full use of only python codes even while calling the non-
python third party library. The ‘Django wrapper’ can be used as following:
 Creating charts (Stacked, Bubble, 2D/3D Pie chart) using HTML/ Javascript codes as a
string to the server
 Creating a SQL database using only python code and interfacing the database abstractly
(OO concept of ‘abstraction’) into the server
The ‘FusionChart Django wrapper’ can create charts using the usual HTML/JavaScript codes
but sending those codes as a string to the server.
Explanation of a Sample using the Wrapper:
To create a chart using the wrapper the user should understand the steps in the codes. The chart
can be used in the project installing the ‘fusioncharts.py’ in the project and applying the classes
and methods under the’ FusionCharts ‘namespace. The charts can be rendered in a webpage
using the server request module of the ‘Django’ wrapper. The code of creating a chart is
explained below in details.
Step1: The HTML/JavaScript codes should be used as a string to create the chart. If the user uses
the ‘FusionCharts’ CDN, then he/she should include the path as a source in the script tag.
Code:
<script type="text/javascript"src="http://static.fusioncharts.com/code/latest/fusioncharts.js">
</script>
The ‘src’ attribute identifies the library link for the official CDN.
Step2: The code to create the chart includes the type of chart, data as well as type of parameters
used in this case.
Code:
Inclusion of Filename: app_name/views.py
Inclusion of `fusioncharts.py`
from fusioncharts import FusionCharts
def chart(request):
column2d = FusionCharts("column2d", "ex1" , "1200", "600", "chart-1", "json",
"""{
"chart":
{
"caption":" Targets of Supermarkets ",
"subCaption":"Top 3 stores in February by revenue",
"numberPrefix":"$",
"theme":"ocean"
},
"data":
[
{
"label":"Bakersfield Central",
"value":"880000"
},
{
"label":"Garden Groove harbour",
"value":"730000"
},
{
"label":"Los Angeles Topanga",
"value":"590000"
},
]
}""")
return render(request, 'index.html', {'output' : column2d.render()})
In the code the arguments of the ‘fusionchart’ identifies Chart type, ID, width, height, format and
source respectively. The chart type is 2d column in this case. The ID identifies the chart in the
HTML source. The data source gives the original values for the chart. IN this case three values
are considered.
Step 3: The URL configuration considers the URL pattern of the chart.
Code:
Inclusion of Filename: app_name/urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.chart, name='demo1'),
]
Step 4: The last step creates a specific decoration for the chart.
Code:
<h3><b><i>FusionChart</i></b></h3>
<div id="2DchartContainer">{{ output|safe }}</div>
The Django wrapper decorates the chart sample importing the JavaScript library in the python
interface only using the python code in the above way.

Mais conteúdo relacionado

Mais procurados

Javascript part1
Javascript part1Javascript part1
Javascript part1Raghu nath
 
R package development, create package documentation isabella gollini
R package development, create package documentation   isabella golliniR package development, create package documentation   isabella gollini
R package development, create package documentation isabella golliniDataFest Tbilisi
 
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13Abu Saleh
 
Design patterns in Magento
Design patterns in MagentoDesign patterns in Magento
Design patterns in MagentoDivante
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Stephan Schmidt
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysqldurai arasan
 
Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0Cathie101
 
Arrays &amp; functions in php
Arrays &amp; functions in phpArrays &amp; functions in php
Arrays &amp; functions in phpAshish Chamoli
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++somu rajesh
 
CPP Programming Homework Help
CPP Programming Homework HelpCPP Programming Homework Help
CPP Programming Homework HelpC++ Homework Help
 

Mais procurados (19)

Angular 2.0 - What to expect
Angular 2.0 - What to expectAngular 2.0 - What to expect
Angular 2.0 - What to expect
 
Javascript part1
Javascript part1Javascript part1
Javascript part1
 
Capstone ms2
Capstone ms2Capstone ms2
Capstone ms2
 
R package development, create package documentation isabella gollini
R package development, create package documentation   isabella golliniR package development, create package documentation   isabella gollini
R package development, create package documentation isabella gollini
 
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
 
Computer Science Assignment Help
 Computer Science Assignment Help  Computer Science Assignment Help
Computer Science Assignment Help
 
SRAVANByCPP
SRAVANByCPPSRAVANByCPP
SRAVANByCPP
 
lab4_php
lab4_phplab4_php
lab4_php
 
Design patterns in Magento
Design patterns in MagentoDesign patterns in Magento
Design patterns in Magento
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysql
 
Header files in c
Header files in cHeader files in c
Header files in c
 
Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0
 
Arrays &amp; functions in php
Arrays &amp; functions in phpArrays &amp; functions in php
Arrays &amp; functions in php
 
C++
C++C++
C++
 
Download It
Download ItDownload It
Download It
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Unix ppt
Unix pptUnix ppt
Unix ppt
 
CPP Programming Homework Help
CPP Programming Homework HelpCPP Programming Homework Help
CPP Programming Homework Help
 

Semelhante a Create Charts with FusionChart Django Wrapper

Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Tony Frame
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfoliomwillmer
 
Top 10 Techniques For React Performance Optimization in 2022.pptx
Top 10 Techniques For React Performance Optimization in 2022.pptxTop 10 Techniques For React Performance Optimization in 2022.pptx
Top 10 Techniques For React Performance Optimization in 2022.pptxBOSC Tech Labs
 
C,c++ interview q&a
C,c++ interview q&aC,c++ interview q&a
C,c++ interview q&aKumaran K
 
Introduction to Google App Engine with Python
Introduction to Google App Engine with PythonIntroduction to Google App Engine with Python
Introduction to Google App Engine with PythonBrian Lyttle
 
Warsaw Frontend Meetup #1 - Webpack
Warsaw Frontend Meetup #1 - WebpackWarsaw Frontend Meetup #1 - Webpack
Warsaw Frontend Meetup #1 - WebpackRadosław Rosłaniec
 
Spring first in Magnolia CMS - Spring I/O 2015
Spring first in Magnolia CMS - Spring I/O 2015Spring first in Magnolia CMS - Spring I/O 2015
Spring first in Magnolia CMS - Spring I/O 2015Tobias Mattsson
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'sAntônio Roberto Silva
 
Flex Daily Solutions @ FITC 2008
Flex Daily Solutions @ FITC 2008Flex Daily Solutions @ FITC 2008
Flex Daily Solutions @ FITC 2008marcocasario
 
Tech Talk - Overview of Dash framework for building dashboards
Tech Talk - Overview of Dash framework for building dashboardsTech Talk - Overview of Dash framework for building dashboards
Tech Talk - Overview of Dash framework for building dashboardsAppsilon Data Science
 
Buffer overflow tutorial
Buffer overflow tutorialBuffer overflow tutorial
Buffer overflow tutorialhughpearse
 
Android application architecture
Android application architectureAndroid application architecture
Android application architectureRomain Rochegude
 
Data visualization in python/Django
Data visualization in python/DjangoData visualization in python/Django
Data visualization in python/Djangokenluck2001
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridGiorgio Cefaro
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrideugenio pombi
 

Semelhante a Create Charts with FusionChart Django Wrapper (20)

Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
Top 10 Techniques For React Performance Optimization in 2022.pptx
Top 10 Techniques For React Performance Optimization in 2022.pptxTop 10 Techniques For React Performance Optimization in 2022.pptx
Top 10 Techniques For React Performance Optimization in 2022.pptx
 
ajax_pdf
ajax_pdfajax_pdf
ajax_pdf
 
ajax_pdf
ajax_pdfajax_pdf
ajax_pdf
 
C,c++ interview q&a
C,c++ interview q&aC,c++ interview q&a
C,c++ interview q&a
 
Introduction to Google App Engine with Python
Introduction to Google App Engine with PythonIntroduction to Google App Engine with Python
Introduction to Google App Engine with Python
 
Warsaw Frontend Meetup #1 - Webpack
Warsaw Frontend Meetup #1 - WebpackWarsaw Frontend Meetup #1 - Webpack
Warsaw Frontend Meetup #1 - Webpack
 
IOC + Javascript
IOC + JavascriptIOC + Javascript
IOC + Javascript
 
Spring first in Magnolia CMS - Spring I/O 2015
Spring first in Magnolia CMS - Spring I/O 2015Spring first in Magnolia CMS - Spring I/O 2015
Spring first in Magnolia CMS - Spring I/O 2015
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 
Flex Daily Solutions @ FITC 2008
Flex Daily Solutions @ FITC 2008Flex Daily Solutions @ FITC 2008
Flex Daily Solutions @ FITC 2008
 
Tech Talk - Overview of Dash framework for building dashboards
Tech Talk - Overview of Dash framework for building dashboardsTech Talk - Overview of Dash framework for building dashboards
Tech Talk - Overview of Dash framework for building dashboards
 
Buffer overflow tutorial
Buffer overflow tutorialBuffer overflow tutorial
Buffer overflow tutorial
 
Android application architecture
Android application architectureAndroid application architecture
Android application architecture
 
Red5 - PHUG Workshops
Red5 - PHUG WorkshopsRed5 - PHUG Workshops
Red5 - PHUG Workshops
 
Data visualization in python/Django
Data visualization in python/DjangoData visualization in python/Django
Data visualization in python/Django
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrid
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrid
 
JPA 2.0
JPA 2.0JPA 2.0
JPA 2.0
 

Create Charts with FusionChart Django Wrapper

  • 1. FusionChart Django Wrapper Definition: Python 2.7 provides some interesting concepts like decorators or wrappers. The function decorators or wrappers change the action of the original function before or after the execution of the function. In this type of case the original function does not modify itself but the working is decorated by the wrapper according to its principal. The easiest example is wrapping a function return by some html/JavaScript tags. If a function returns some name as output, the decorator can modify it using the <p>, <b>, <i> tags etc. Example:: Input: def get_result(intro): return “Captain America, {0} in civil war” .format (intro) def pb_ decorate (func): def func_wrap(intro): return “ <p><b>{0}</p></b>” .format (func(intro)) return func_wrap mah_movie= pb_decorate ( get_result) print mah_movie ( “Chris Evans”)
  • 2. Output: <p><b> Captain America, Chris Evans in civil war</b></p> However, calling the decorating function has a clear shortcut. This kind of function can be identified prepending ‘@’ in it. In the above example the decorator should be @pb_decorate (). Django wrapper: This special type of decorator or wrapper provides the advantage of class based views over the function based views. The wrapper organizes server side HTTP methods like Get, Post etc using separate methods instead of branching ( if/else / for/ while). The wrapper also provides object oriented process like ‘mixins’, ‘prefork working module’ etc. The wrapper uses toolkit and multiple inheritance (‘mixins’) to increase the extensibility and flexibility of the class based attributes. CODE: from django.http import HttpResponse from django.views.generic import View class GreetView(View): greeting = "Nice Day" def get(self, request): return HttpResponse ( self.greeting ) In the above code The URL resolver of the Django wrapper expects the arguments from a function and not a class therefore the view method serves as the opening point of the class. The
  • 3. view method creates an interface for dispatch () method to identify the type of request (Get/Post/not allowed response) and works according to it. Purpose of the Wrapper: The python module (wrapper) creates an interface between python and a third party library. The advantage of this kind of module is the full use of only python codes even while calling the non- python third party library. The ‘Django wrapper’ can be used as following:  Creating charts (Stacked, Bubble, 2D/3D Pie chart) using HTML/ Javascript codes as a string to the server  Creating a SQL database using only python code and interfacing the database abstractly (OO concept of ‘abstraction’) into the server The ‘FusionChart Django wrapper’ can create charts using the usual HTML/JavaScript codes but sending those codes as a string to the server. Explanation of a Sample using the Wrapper: To create a chart using the wrapper the user should understand the steps in the codes. The chart can be used in the project installing the ‘fusioncharts.py’ in the project and applying the classes and methods under the’ FusionCharts ‘namespace. The charts can be rendered in a webpage using the server request module of the ‘Django’ wrapper. The code of creating a chart is explained below in details. Step1: The HTML/JavaScript codes should be used as a string to create the chart. If the user uses the ‘FusionCharts’ CDN, then he/she should include the path as a source in the script tag.
  • 4. Code: <script type="text/javascript"src="http://static.fusioncharts.com/code/latest/fusioncharts.js"> </script> The ‘src’ attribute identifies the library link for the official CDN. Step2: The code to create the chart includes the type of chart, data as well as type of parameters used in this case. Code: Inclusion of Filename: app_name/views.py Inclusion of `fusioncharts.py` from fusioncharts import FusionCharts def chart(request): column2d = FusionCharts("column2d", "ex1" , "1200", "600", "chart-1", "json", """{ "chart": { "caption":" Targets of Supermarkets ", "subCaption":"Top 3 stores in February by revenue", "numberPrefix":"$",
  • 5. "theme":"ocean" }, "data": [ { "label":"Bakersfield Central", "value":"880000" }, { "label":"Garden Groove harbour", "value":"730000" }, { "label":"Los Angeles Topanga", "value":"590000" }, ]
  • 6. }""") return render(request, 'index.html', {'output' : column2d.render()}) In the code the arguments of the ‘fusionchart’ identifies Chart type, ID, width, height, format and source respectively. The chart type is 2d column in this case. The ID identifies the chart in the HTML source. The data source gives the original values for the chart. IN this case three values are considered. Step 3: The URL configuration considers the URL pattern of the chart. Code: Inclusion of Filename: app_name/urls.py from django.conf.urls import url from . import views urlpatterns = [ url(r'^$', views.chart, name='demo1'), ] Step 4: The last step creates a specific decoration for the chart. Code: <h3><b><i>FusionChart</i></b></h3> <div id="2DchartContainer">{{ output|safe }}</div>
  • 7. The Django wrapper decorates the chart sample importing the JavaScript library in the python interface only using the python code in the above way.