#NEWLINE# @ add_source_code_and_doc #NEWLINE# def basicpie( request , title , code , doc , sidebar_items ) : #NEWLINE# #INDENT# '\n    A Basic Pie Chart\n    ------------------\n    This is a pie chart of temperature by month for Boston. \n    \n    Points to note:\n\n    - ``terms`` is a list of all fields (both for x-axis and y-axis) \n      to retrieve from the model.\n    - Remember that for a Chart, the x and y terms in the ``series_options`` \n      are written as ``x: [y, ...]`` pairs.\n    - Any valid items in the `Highcharts options object\n      <http://www.highcharts.com/ref/>`_ are valid ``chart_options``.\n    - We use the ``x_mapf_sortf_mts`` parameter to convert the month numbers \n      retrieved from the database to month names.\n      \n    Note: This demo is to demonstrate the use of the API and not to teach \n    you data analysis and data presentation skills. Not all charts plotted \n    in this demo may make sense in real life applications. But they can \n    still be useful in demonstrating the API.\n    \n    ' #NEWLINE# ds = DataPool ( series = [ { #NEWLINE# #INDENT# 'options' : { #NEWLINE# #INDENT# 'source' : MonthlyWeatherByCity . objects . all ( ) , #NEWLINE# #UNINDENT# } , #NEWLINE# 'terms' : [ 'month' , 'boston_temp' ] , #NEWLINE# #UNINDENT# } ] ) #NEWLINE# def monthname( month_num ) : #NEWLINE# #INDENT# names = { #NEWLINE# #INDENT# 1 : 'Jan' , #NEWLINE# 2 : 'Feb' , #NEWLINE# 3 : 'Mar' , #NEWLINE# 4 : 'Apr' , #NEWLINE# 5 : 'May' , #NEWLINE# 6 : 'Jun' , #NEWLINE# 7 : 'Jul' , #NEWLINE# 8 : 'Aug' , #NEWLINE# 9 : 'Sep' , #NEWLINE# 10 : 'Oct' , #NEWLINE# 11 : 'Nov' , #NEWLINE# 12 : 'Dec' , #NEWLINE# #UNINDENT# } #NEWLINE# return names [ month_num ] #NEWLINE# #UNINDENT# cht = Chart ( datasource = ds , series_options = [ { #NEWLINE# #INDENT# 'options' : { #NEWLINE# #INDENT# 'type' : 'pie' , #NEWLINE# 'stacking' : False , #NEWLINE# #UNINDENT# } , #NEWLINE# 'terms' : { #NEWLINE# #INDENT# 'month' : [ 'boston_temp' ] , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ] , chart_options = { #NEWLINE# #INDENT# 'title' : { #NEWLINE# #INDENT# 'text' : 'Monthly Temperature of Boston' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , x_sortf_mapf_mts = ( None , monthname , False ) ) #NEWLINE# return render_to_response ( 'chart_code.html' , { #NEWLINE# #INDENT# 'chart_list' : cht , #NEWLINE# 'code' : code , #NEWLINE# 'title' : title , #NEWLINE# 'doc' : doc , #NEWLINE# 'sidebar_items' : sidebar_items , #NEWLINE# #UNINDENT# } )