def vote_results_barchar request from pygooglechart import StackedHori

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
def vote_results_barchart(request):
from pygooglechart import StackedHorizontalBarChart
p = get_object_or_404(Poll, published=True)
max_range = max([x.votes for x in p.choice_set.all()])
chart = StackedHorizontalBarChart((len(p.choice_set.all())**2)*20, len(p.choice_set.all())*30+30, x_range=(0, max_range+5))
chart.set_bar_width(30)
chart.add_data([x.votes for x in p.choice_set.all()])
chart.add_vertical_range('22ff22', 1, 7)
png = urllib.urlopen(chart.get_url())
return HttpResponse(png, mimetype='image/png')