def breach_attempt_chart_view(request): breach_attempt_data = PivotDataPool(series=[{ 'options': { 'source': Auth.objects.filter(username='******'), 'categories': ['success'], 'legend_by': 'username', 'top_n_per_cat': 3, }, 'terms': { 'avg_breach': Avg('success') } }]) chart_obj = PivotChart(datasource=breach_attempt_data, series_options=[{ 'options': { 'type': 'column', 'stacking': True }, 'terms': ['avg_breach'] }], chart_options={ 'title': { 'text': 'Breach Report' }, 'xAxis': { 'title': { 'text': 'x--------axis' } } }) return render(request, 'chart_represent.html', {'chart_object': chart_obj})
def Single_errors_graph2_ViewByMonth(request): if 'errnamesess' in request.session: errname = request.session['errnamesess'] else: print "SOmething wrong in session variable" ds = PivotDataPool( series=[ {'options': { 'source': datewisedetailknownerrcounts.objects.filter(err_name=errname), 'categories': ['month_name'], 'legend_by': 'month_name'}, 'terms': {'Total_ErrCounts': Sum('err_counts') }}]) pivcht = PivotChart( datasource=ds, series_options=[ {'options': { 'type': 'column', 'stacking': True, 'xAxis': 0, 'yAxis': 0}, 'terms': ['Total_ErrCounts']}]) # end_code return render_to_response('ErrorsSingleGraph.html', { 'chart_list': pivcht, 'code': "newcode", 'title': "Error View by Monthwise:-", 'doc': "This Chart Displays selected error name pivot group by Month Name", 'sidebar_items': "SIdeBarItem"})
def get_line_chart(pts, symbol, parameter): #sorting hack for pt in pts: if pt.percent_correct == 100.0: pt.percent_correct = 99.9 ds = PivotDataPool(series=[{ 'options': { 'source': pts.order_by('-' + parameter).all(), 'categories': parameter }, 'terms': { 'tot_items': Count(parameter) } }]) pivcht = PivotChart(datasource=ds, series_options=[{ 'options': { 'type': 'column' }, 'terms': ['tot_items'] }], chart_options={ 'title': { 'text': 'Distribution of ' + parameter + ' %s' }, 'xAxis': { 'title': { 'text': 'Percent' } } }) return pivcht
def pivot_with_legend(request, title, code, doc, sidebar_items): """ Pivot Chart with legend by field. This pivot chart plots total sale quantity of books in each city legended by the book genre name. """ # start_code ds = PivotDataPool( series=[ {'options': { 'source': SalesHistory.objects.all(), 'categories': 'bookstore__city__city', 'legend_by': 'book__genre__name'}, 'terms': { 'tot_sales': Sum('sale_qty')}}]) pivcht = PivotChart( datasource=ds, series_options=[ {'options': { 'type': 'column', 'stacking': True, 'xAxis': 0, 'yAxis': 0}, 'terms': ['tot_sales']}]) # end_code return render_to_response('chart_code.html', { 'chart_list': pivcht, 'code': code, 'title': title, 'doc': doc, 'sidebar_items': sidebar_items})
def cust_month_pivot(request): #start_code ds = PivotDataPool(series=[{ 'options': { 'source': datewiseerrcounts.objects.all(), 'categories': ['appsrv_name', 'month_name'], 'legend_by': 'cust_name' }, 'terms': { 'Total_ErrCounts': Sum('err_counts') } }]) pivcht = PivotChart(datasource=ds, series_options=[{ 'options': { 'type': 'column', 'stacking': True, 'xAxis': 0, 'yAxis': 0 }, 'terms': ['Total_ErrCounts'] }]) # end_code return render_to_response( 'centurionapi/graphs/CustPivotChart.html', { 'chart_list': pivcht, 'code': "newcode", 'title': "Sum Errors Counts by Customer Name", 'doc': 'Total Errors Counts by Customer Name', 'sidebar_items': "sidebaritems" })
def Single_errors_graph2(request): errname= request.GET.get('err_name') request.session['errnamesess'] = errname print request.session['errnamesess'] ds = PivotDataPool( series=[ {'options': { 'source': datewisedetailknownerrcounts.objects.filter(err_name=errname), 'categories': ['appsrv_name'], 'legend_by': 'appsrv_name'}, 'terms': {'Total_ErrCounts': Sum('err_counts') }}]) pivcht = PivotChart( datasource=ds, series_options=[ {'options': { 'type': 'column', 'stacking': True, 'xAxis': 0, 'yAxis': 0}, 'terms': ['Total_ErrCounts']}]) # end_code return render_to_response('ErrorsSingleGraph.html', { 'chart_list': pivcht, 'code': "newcode", 'title': "SingleErrorChart", 'doc': "This Chart Displays selected error name pivot group by App Server Name", 'sidebar_items': "SIdeBarItem"})
def date_month_pivot(request): #start_code ds = PivotDataPool(series=[{ 'options': { 'source': datewiseerrcounts.objects.all(), 'categories': ['cust_name', 'month_name'], 'legend_by': 'date_stamp' }, 'terms': { 'Total_ErrCounts': Sum('err_counts') } }]) pivcht = PivotChart(datasource=ds, series_options=[{ 'options': { 'type': 'column', 'stacking': True, 'xAxis': 0, 'yAxis': 0 }, 'terms': ['Total_ErrCounts'] }]) # end_code return render_to_response( 'centurionapi/graphs/DateWiseErr.html', { 'chart_list': pivcht, 'code': "code", 'title': "Error Counts by Each day of Months", 'doc': "This chart represent errors count by each day of months", 'sidebar_items': "sidebars" })
def detail_errs_cust_pivot(request): #start_code ds = PivotDataPool(series=[{ 'options': { 'source': datewisedetailknownerrcounts.objects.all(), 'categories': ['appsrv_name', 'cust_name'], 'legend_by': 'err_name' }, 'terms': { 'Total_ErrCounts': Sum('err_counts') } }]) pivcht = PivotChart(datasource=ds, series_options=[{ 'options': { 'type': 'column', 'stacking': True, 'xAxis': 0, 'yAxis': 0 }, 'terms': ['Total_ErrCounts'] }]) # end_code return render_to_response( 'centurionapi/graphs/DetailErrsRepo.html', { 'chart_list': pivcht, 'code': "code", 'title': "Error Count Chart Based on Customer", 'doc': "This chart shows error name and its counts against each customer.", 'sidebar_items': "sidebar_items" })
def entry_pivot_chart_view(request): # Step 1: Create a PivotDataPool with the data we want to retrieve. entrypivotdata = PivotDataPool(series=[{ 'options': { 'source': Entry.objects.all(), 'categories': ['date'], 'legend_by': 'category', }, 'terms': { 'sum_amount': Sum('amount'), } }]) # Step 2: Create the PivotChart object rainpivcht = PivotChart(datasource=entrypivotdata, series_options=[{ 'options': { 'type': 'column', 'stacking': True }, 'terms': ['sum_amount'] }], chart_options={ 'title': { 'text': 'Ausgaben per Datum und Kategorie' }, 'xAxis': { 'title': { 'text': 'Month' } } }) # Step 3: Send the PivotChart object to the template. return render(request, 'graph.html', { 'rainpivchart': rainpivcht, })
def appsrv_month_pivot(request): #start_code ds = PivotDataPool(series=[{ 'options': { 'source': datewiseerrcounts.objects.all(), 'categories': ['cust_name', 'month_name'], 'legend_by': 'appsrv_name' }, 'terms': { 'Total_ErrCounts': Sum('err_counts') } }]) pivcht = PivotChart(datasource=ds, series_options=[{ 'options': { 'type': 'column', 'stacking': True, 'xAxis': 0, 'yAxis': 0 }, 'terms': ['Total_ErrCounts'] }]) # end_code return render_to_response( 'centurionapi/graphs/AppsrvPivotChart.html', { 'chart_list': pivcht, 'code': 'AppserverChart', 'title': 'Application Server Wise Error Reports', 'doc': "This Chart Displays selected error Counts by Application Server name ", 'sidebar_items': "SIdeBarItem" })
def simplepivot(request, title, code, doc, sidebar_items): """ A simple pivot chart. Points to notice: - You can use the default django convention of double underscore (__) to *follow* to the fields in different models. """ # start_code ds = PivotDataPool( series=[ {'options': { 'source': SalesHistory.objects.all(), 'categories': 'bookstore__city__city'}, 'terms': { 'tot_sales': Sum('sale_qty')}}]) pivcht = PivotChart( datasource=ds, series_options=[ {'options': { 'type': 'column'}, 'terms': ['tot_sales']}]) # end_code return render_to_response('chart_code.html', { 'chart_list': pivcht, 'code': code, 'title': title, 'doc': doc, 'sidebar_items': sidebar_items})
def rainfall_pivot_chart_view(request): #Step 1: Create a PivotDataPool with the data we want to retrieve. rainpivotdata = \ PivotDataPool( series = [{'options': { 'source': Sales_by_store_by_category.objects.all(), 'categories': ['store', 'manager'], 'legend_by': 'category'}, 'terms': { 'sum_total_sales': Sum('total_sales'), #'legend_by': ['category'], # 'top_n_per_cat': 3 }}]) #Step 2: Create the PivotChart object rainpivcht = \ PivotChart( datasource = rainpivotdata, series_options = [{'options':{ 'type': 'column', 'stacking': True}, 'terms':[ 'sum_total_sales']}], chart_options = {'title': { 'text': 'Rain by Month in top 3 cities'}, 'xAxis': { 'title': { 'text': 'Month'}}}) #Step 3: Send the PivotChart object to the template. return render(request, 'app_pagila/Sales_store_category.html', {'rainpivchart': rainpivcht})
def get_chart(datasource, graph, keys, title, xaxis): """ graph: line / pie """ terms = [keys[x] for x in keys.keys()] return PivotChart( datasource=datasource, series_options=[{ 'options': { 'type': graph, 'stacking': False }, 'terms': terms }], chart_options={ 'title': { 'text': title}, 'credits': { 'enabled': False }, 'xAxis': { 'title': { 'text': xaxis}}, 'yAxis': { 'title': { 'text': ''}}, })
def dashboard(request): #Step 1: Create a DataPool with the data we want to retrieve. need_data = PivotDataPool(series=[{ 'options': { 'source': Need.objects.all(), 'categories': ['temporary_tent'], 'legend_by': 'unit', 'top_n_per_cat': 5, }, 'terms': { 'avg_rain': Sum('temporary_tent'), } }]) # Step 2: Create the PivotChart object cht = PivotChart(datasource=need_data, series_options=[{ 'options': { 'type': 'column', 'stacking': True }, 'terms': ['avg_rain'] }], chart_options={ 'title': { 'text': 'Rain by Month in top 3 cities' }, 'xAxis': { 'title': { 'text': 'sum of need' } } }) return render(request, 'webgis/dashboard.html', {'content': cht})
def expensePivotChart(request): expensepivotdata = \ PivotDataPool( series = [ {'options': { 'source': Expense.objects.all() 'categories': ['store']}, 'terms': { 'total': Sum('price'), 'legend_by': ['store'], 'top_n_per_cat': 1000000}} ]) expensepivcht = \ PivotChart( datasource = expensepivotdata, series_options = [{'options': { 'type': 'column', 'stacking': False}, 'terms': [ 'sum_price']}], chart_options = { 'title': { 'text': 'Cost by Store'}, 'xAxis': { 'title': { 'text': '$'}}}) return render_to_response({'expensepivchart': expensepivcht})
def get_province_trend_lines(): """ Get category datapool data fot datachartit Arguments: In: user Out: school numbers object """ data = ProjectSingle.objects.all() ds = PivotDataPool(series=[ { 'options': { 'source': data, 'categories': ['school__id'], 'legend_by': [ 'project_grade__grade', ] }, 'terms': { 'number': Count('project_grade'), } }, ], sortf_mapf_mts=(None, map_school_name, True)) cht = PivotChart(datasource=ds, series_options=[ { 'options': { 'type': 'column', 'stacking': True }, 'terms': ['number'] }, ], chart_options={ 'title': { 'text': '学校-评级数据统计' }, 'xAxis': { 'title': { 'text': '参赛学校' }, 'labels': { 'step': 1, 'rotation': 45, 'align': 'bottom' }, }, 'yAxis': { 'title': { 'text': '评级数量' }, 'allowDecimals': False }, }) return cht
def pivot(request): ds = PivotDataPool(series=[{ 'options': { 'source': SalesHistory.objects.all(), 'categories': 'bookstore__city__city', }, 'terms': { 'Max Books/Sale': Max('sale_qty'), 'Total Books Sold': Sum('sale_qty'), 'Min Books/Sale': Min('sale_qty'), 'Total Sales $': Sum('price'), }, }]) pivcht = PivotChart(datasource=ds, series_options=[{ 'options': { 'type': 'bar' }, 'terms': [ 'Min Books/Sale', 'Max Books/Sale', 'Total Books Sold', 'Total Sales $' ], }], chart_options={ 'title': { 'text': 'Sales Data' }, 'subtitle': { 'text': 'All Points', }, 'legend': { 'layout': 'vertical', 'align': 'right', 'verticalAlign': 'center', 'x': -10, 'y': 80, 'floating': True, 'borderWidth': 1, "backgroundColor": '#EEEEEE', 'shadow': True, 'reversed': True }, 'plotOptions': { 'bar': { 'dataLabels': { 'enabled': True }, 'pointPadding': 1, 'borderWidth': 10, 'borderRadius': 11 } }, }) return render_to_response('pivot.html', {'pivot': pivcht})
def top_ten_products(request): #d = json.loads(request.body) #if d['storeid'] is None: # storeid = 1; #else: print "here" if 'store_selected' in request.GET and request.GET['store_selected']: store_selected = request.GET['store_selected'] print store_selected; else: store_selected = "All" if (store_selected=="All"): transaction_list= Transaction.objects.all() else: transaction_list= Transaction.objects.filter(store_id=store_selected) store_list = Store.objects.all() productrevenue = \ PivotDataPool( series= [{'options': { 'source': transaction_list, 'categories' : ['product_id']}, 'terms': { 'avg_revenue': Avg('selling_price')}}], #'top_n' : 10}}] top_n = 10, top_n_term = 'avg_revenue') transaction_stats = \ PivotChart( datasource = productrevenue, series_options = [{'options':{ 'type': 'column', 'stacking': True}, 'terms':[ 'avg_revenue'] }], chart_options = {'title': { 'text': 'Revenue by Product'}, 'xAxis': { 'title': { 'text': 'Product ID'}}}) return render(request,'top_tenProducts.html', { 'transaction_stats': transaction_stats, 'store_list' : store_list } )
def statistic_python_version(request): """ Statistics """ from chartit import DataPool, Chart, PivotDataPool, PivotChart from django.db.models import F, FloatField, Sum from django.db.models import Count import datetime sites = Site.objects.filter(enable=True) ds = PivotDataPool(series=[{ 'options': { 'source': sites, 'categories': 'python_version' }, 'terms': { 'python': Count('pk') } }]) python_version_chart = PivotChart( datasource=ds, series_options=[{ 'options': { 'type': 'column' }, 'terms': ['python'] }], chart_options={ 'title': { 'text': 'Python : Python Version' }, 'xAxis': { 'title': { 'text': 'Python2Sites : %s' % datetime.datetime.now() } }, 'yAxis': { 'title': { 'text': 'Value' } }, 'legend': { 'enabled': True }, 'credits': { 'enabled': False } }, ) return render(request, "statistic_python_version.html", locals())
def get_grade_lines(user): """ Get category datapool data fot datachartit Arguments: In: user Out: grade_pies object """ data = ProjectSingle.objects.filter(adminuser=user) ds = PivotDataPool(series=[ { 'options': { 'source': data, 'categories': ['year'], 'legend_by': [ 'project_grade__grade', ] }, 'terms': { 'number': Count('project_grade'), } }, ], ) cht = PivotChart(datasource=ds, series_options=[ { 'options': { 'type': 'column', 'stacking': False }, 'terms': ['number'] }, ], chart_options={ 'title': { 'text': u'历史项目级别数据统计' }, 'xAxis': { 'title': { 'text': u'年份' }, }, 'yAxis': { 'title': { 'text': u'获奖评级' }, 'allowDecimals': False }, }) return cht
def pivot_mapf(_, title, code, doc, sidebar_items): """ Pivot Chart with ``sortf_mapf_mts`` defined to map custom names for x-axis and to customize the x-axis sorting. In this chart we would like to plot region:city instead of state:city. However region is not available in the database. So custom mapf function comes to the rescue. Points to note: - Note that ``mapf`` receives a tuple and returns a tuple. This is true even when ``categories`` is a single element. - ``mts=True`` causes the elements to be mapped and then sorted. So all the N region cities are on the left and the S region cities are on the right hand side of the plot. """ # start_code def region_state(x): region = {'CA': 'S', 'MA': 'N', 'TX': 'S', 'NY': 'N'} return (region[x[0]], x[1]) ds = PivotDataPool(series=[{ 'options': { 'source': SalesHistory.objects.all(), 'categories': ['bookstore__city__state', 'bookstore__city__city'], 'legend_by': 'book__genre__name' }, 'terms': { 'tot_sales': Sum('sale_qty') } }], sortf_mapf_mts=(None, region_state, True)) pivcht = PivotChart(datasource=ds, series_options=[{ 'options': { 'type': 'column', 'stacking': True }, 'terms': ['tot_sales'] }]) # end_code return render_to_response( 'chart_code.html', { 'chart_list': pivcht, 'code': code, 'title': title, 'doc': doc, 'sidebar_items': sidebar_items })
def pivot_datetime_related(_, title, code, doc, sidebar_items): """ Pivot chart with DateTimeField from related model ------------------------------------------------- This chart shows total sales based on when book was published. The data is limited to books published during June 1st-20th, 2010 for brevity. Note that we filter down the possible values using date range queries instead of slicing. Slicing the query results in an error. Slicing in Chart() charts however is fine! """ # start_code ds = PivotDataPool(series=[{ 'options': { 'source': SalesHistory.objects.filter( book__published_at__year=2010, book__published_at__month=6, ), 'categories': 'book__published_at', 'legend_by': 'book__title', }, 'terms': { 'tot_sales': Sum('sale_qty'), } }]) pivcht = PivotChart(datasource=ds, series_options=[{ 'options': { 'type': 'column', 'stacking': True, 'xAxis': 0, 'yAxis': 0, }, 'terms': ['tot_sales'] }]) # end_code return render_to_response( 'chart_code.html', { 'chart_list': pivcht, 'code': code, 'title': title, 'doc': doc, 'sidebar_items': sidebar_items })
def monthly_stats(request): #d = json.loads(request.body) #if d['storeid'] is None: # storeid = 1; #else: print "here" if 'store_selected' in request.GET and request.GET['store_selected']: store_selected = request.GET['store_selected'] print store_selected; else: store_selected = "All" if (store_selected=="All"): transaction_list= Transaction.objects.all() else: transaction_list= Transaction.objects.filter(store_id=store_selected) store_list = Store.objects.all() # transaction_list = Transaction.objects.filter(store_id=1) # transaction_list = Transaction.objects.all() dateRevenue = \ PivotDataPool( series= [{'options': { 'source': transaction_list, 'categories' : ['transaction_date']}, 'terms': { 'avg_revenue': Avg('selling_price')}}]) transaction_stats = PivotChart( datasource = dateRevenue, series_options = [{'options':{ 'type': 'line'}, 'terms':[ 'avg_revenue'] }], chart_options = {'title': { 'text': 'Spend over Last 30 days'}}) return render(request,'monthly_stats.html', { 'transaction_stats': transaction_stats, 'store_list' : store_list } )
def pivot_top_n(_, title, code, doc, sidebar_items): """ Pivot Chart limited to top few items. In this chart the sales quanity is plotted w.r.t state/city but the chart is limited to only top 5 cities witht the highest sales. Points to note: - These charts are helpful in cases where there is a long *tail* and we only are interested in the top few items. - ``top_n_term`` is always required. If there are multiple items, it will elimnate confusion regarding what the term the chart needs to be limited by. """ # start_code ds = PivotDataPool(series=[{ 'options': { 'source': SalesHistory.objects.all(), 'categories': ['bookstore__city__state', 'bookstore__city__city'], 'legend_by': 'book__genre__name' }, 'terms': { 'tot_sales': Sum('sale_qty') } }], top_n=5, top_n_term='tot_sales') pivcht = PivotChart(datasource=ds, series_options=[{ 'options': { 'type': 'column', 'stacking': True, 'xAxis': 0, 'yAxis': 0 }, 'terms': ['tot_sales'] }]) # end_code return render_to_response( 'chart_code.html', { 'chart_list': pivcht, 'code': code, 'title': title, 'doc': doc, 'sidebar_items': sidebar_items })
def index(request): #Step 1: Create a DataPool with the data we want to retrieve. workoutdata = \ PivotDataPool( series= [{ 'options': { 'source': Workout.objects.all(), 'categories': ['type__name'], }, 'terms': { 'total_distance' : Sum('distance') } } ]) #Step 2: Create the Chart object cht = PivotChart(datasource=workoutdata, series_options=[{ 'options': { 'type': 'column', 'stacking': False }, 'terms': ['total_distance'] }], chart_options={ 'title': { 'text': 'Hoeveel afstand per type' }, 'xAxis': { 'title': { 'text': 'Type' } } }) latest_workout_list = Workout.objects.all().order_by('-date')[:30] wmanager = WorkoutsManager() months = wmanager.get_total_distances_aggregated_by_month() context = { 'latest_workout_list': latest_workout_list, 'months': months, 'workoutchart': cht } return render(request, 'workouts/index.html', context)
def get_directional_change_chart(bs, denom, symbol, start_time): if settings.MAKE_TRADES: pcs = PerformanceComp.objects.filter( symbol=symbol, created_on__gte=start_time, price_timerange_start__isnull=False).order_by('id') else: pcs = PerformanceComp.objects.filter( symbol=symbol, created_on__gte=start_time, price_timerange_start__isnull=False).order_by('id') pct_dir_same = int(100.0 * sum([pc.directionally_same_int for pc in pcs]) / pcs.count()) ds = PivotDataPool(series=[{ 'options': { 'source': pcs, 'categories': 'created_on_str' }, 'terms': { 'total_value': Sum('directionally_same_int') } }]) pivcht = PivotChart(datasource=ds, series_options=[{ 'options': { 'type': 'line', 'xAxis': 0, 'yAxis': 0 }, 'terms': ['total_value'] }], chart_options={ 'title': { 'text': 'Algorithm vs Reality: Directionally Same ' + str(pct_dir_same) + '% of time ' }, 'xAxis': { 'title': { 'text': 'Time' } }, 'terms': ['total_value'] }) return pivcht
def get_trade_profitability_chart(bs, denom, symbol, start_time): if settings.MAKE_TRADES: trades = Trade.objects.exclude(created_on_str="").filter( symbol=symbol, created_on__gte=start_time).filter( status__in=['fill', 'open', 'error']).order_by('id') else: trades = Trade.objects.exclude(created_on_str="").filter( symbol=symbol, created_on__gte=start_time).order_by('id') ds = PivotDataPool(series=[{ 'options': { 'source': trades, 'categories': 'created_on_str', 'legend_by': 'status' }, 'terms': { 'total_value': Sum('btc_net_profit') } }]) pivcht = PivotChart(datasource=ds, series_options=[{ 'options': { 'type': 'column', 'stacking': True, 'xAxis': 0, 'yAxis': 0 }, 'terms': ['total_value'] }], chart_options={ 'title': { 'text': 'Trade Profitability over time (BTC) ' }, 'xAxis': { 'title': { 'text': 'Time' } }, 'terms': ['total_value'] }) return pivcht
def pivot_with_datefield(_, title, code, doc, sidebar_items): """ Pivot chart with DateField -------------------------- This chart shows total sales of one book per date. Note that we filter down the possible values using date range queries instead of slicing. Slicing the query results in an error. Slicing in Chart() charts however is fine! """ # start_code ds = PivotDataPool(series=[{ 'options': { 'source': SalesHistory.objects.filter( book=Book.objects.filter(title="Hyperspace"), sale_date__year=2010, sale_date__month=10, ), 'categories': 'sale_date' }, 'terms': { 'tot_sales': Sum('sale_qty') } }]) pivcht = PivotChart(datasource=ds, series_options=[{ 'options': { 'type': 'column' }, 'terms': ['tot_sales'] }]) # end_code return render_to_response( 'chart_code.html', { 'chart_list': pivcht, 'code': code, 'title': title, 'doc': doc, 'sidebar_items': sidebar_items })
def pivot_multi_category(_, title, code, doc, sidebar_items): """ Pivot Chart with multiple categories. In this chart the total sale quantity is plotted with respect to state and city. Points to note: - You can add any number of categories and legend_by entries in a list. - **Order matters**! Retrieving state and then city may yield different results compared to retrieving city and state depending on what you are trying to plot. """ # start_code ds = PivotDataPool(series=[{ 'options': { 'source': SalesHistory.objects.all(), 'categories': ['bookstore__city__state', 'bookstore__city__city'], 'legend_by': 'book__genre__name' }, 'terms': { 'tot_sales': Sum('sale_qty') } }]) pivcht = PivotChart(datasource=ds, series_options=[{ 'options': { 'type': 'column', 'stacking': True, 'xAxis': 0, 'yAxis': 0 }, 'terms': ['tot_sales'] }]) # end_code return render_to_response( 'chart_code.html', { 'chart_list': pivcht, 'code': code, 'title': title, 'doc': doc, 'sidebar_items': sidebar_items })
def total_reviews_per_room(request): """ View function for displaying pivot chart on page. """ room_pivot_data = PivotDataPool(series=[{ 'options': { 'source': CsvExport.objects.only("room_type", "reviews"), 'categories': ['room_type'], 'legend_by': 'room_type', 'top_n_per_cat': 100, }, 'terms': { 'total_reviews': Sum('reviews'), } }]) room_pivot_chart = PivotChart(datasource=room_pivot_data, series_options=[{ 'options': { 'type': 'column', 'stacking': True }, 'terms': ['total_reviews'] }], chart_options={ 'title': { 'text': 'Total reviews per room type' }, 'xAxis': { 'title': { 'text': 'Type of room' } }, 'yAxis': { 'title': { 'text': 'Reviews' } } }) # Renders the HTML template total_reviewsroom.html and pivotchart. return render_to_response('charts/total_reviewsroom.html', {'roompivotchart': room_pivot_chart})