This post is really old so hope i'm not questioning into the void, but I am 
2-weeks new to django and trying to figure out the final step to insert the 
reportlab charts into the django template - the 
cookbook<https://code.djangoproject.com/wiki/Charts> entry 
is exceedingly clear about views.py and urls.py, but i'm struggling with 
the html template.

#views.py
def barChart(request, word_id):
    from charts import BarChartDrawing

    word = get_object_or_404(Word, pk=word_id)
    e = word.choice_set.get(perspective='East')
    w = word.choice_set.get(perspective='West')
    b = word.choice_set.get(perspective='Both')
    data_string = `e.votes` + `w.votes` + `b.votes`

    chart = BarChartDrawing(data =[e.votes, w.votes, b.votes], 
title=word.word_text)
    binaryStuff = chart.asString('gif')

    return render_to_response('templates/myapp/barChart.html', {'word': word, 
'binaryStuff': binaryStuff)


#urls.py
url(r'^(?P<pk>\d+)/barchart/$', DetailView.as_view(model=Word,
    template_name='templates/myapp/barChart.html'), name='barChart')

#barchart.html
{% extends "templates/myapp/base.html" %}

{% block title %}{{ block.super}}: {{ word.word_text }}{% endblock title %}

{% block content %}

  <div><img src="{{ binaryStuff }}" /></div>
  <a href="{% url templates_home %}">Return to Home</a>.

{% endblock content %}

many thanks,
-dharol

On Friday, September 8, 2006 5:23:46 PM UTC-5, Andy Robinson wrote:
>
> Hi all,
>
> I have just added a Wiki page under the Cookbook section showing how to
> create dynamic charts using ReportLab's graphics library.  It seems not
> many people know about our chart library, which has been serving
> financial charts in big firms for years.  In any event the Django
> integration is trivial.
>
> If anyone else wants to give this a try I would be very grateful for
> feedback and will try to deal with any questions promptly.
>
> Andy Robinson
> ReportLab
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-developers/-/W53QFCV7a7AJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to