bar charts

48 views
Skip to first unread message

kenneth gonsalves

unread,
Nov 7, 2011, 4:57:00 AM11/7/11
to django-users
hi,

what do people use to display bar charts in their sites?
--
regards
Kenneth Gonsalves

--
regards
Kenneth Gonsalves

Kevin Anthony

unread,
Nov 7, 2011, 5:04:32 AM11/7/11
to django...@googlegroups.com

Google charts api

Kevin
Please excuse brevity, sent from phone

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

kenneth gonsalves

unread,
Nov 7, 2011, 7:39:21 AM11/7/11
to django...@googlegroups.com
On Mon, 2011-11-07 at 00:04 -0500, Kevin Anthony wrote:
> Google charts api
>
>

any clues on how to integrate this with django?
--
regards
Kenneth Gonsalves

skys...@gmail.com

unread,
Nov 7, 2011, 8:01:48 AM11/7/11
to django...@googlegroups.com, kenneth gonsalves
On 2011年11月07日 12:57, kenneth gonsalves wrote:
> hi,
>
> what do people use to display bar charts in their sites?
a lot choices, like html5 chart, flash chart.

amchart,zingchart, i'm trying to use zingchart in my site now, it
provide both flash and html5 solution.

Joey Espinosa

unread,
Nov 7, 2011, 9:28:08 AM11/7/11
to django...@googlegroups.com
Kenneth,

It's a Google API. Like other Google tools, you can connect using google.load() within JavaScript code. It wouldn't integrate directly with Django, but rather through your templates by using JavaScript.
--
Joey "JoeLinux" Espinosa




--
regards
Kenneth Gonsalves

Joey Espinosa

unread,
Nov 7, 2011, 9:28:37 AM11/7/11
to django...@googlegroups.com
Here's the Quick Start page: http://goo.gl/g5I7X

--
Joey "JoeLinux" Espinosa




On Mon, Nov 7, 2011 at 2:39 AM, kenneth gonsalves <law...@thenilgiris.com> wrote:
--
regards
Kenneth Gonsalves

kenneth gonsalves

unread,
Nov 7, 2011, 10:16:58 AM11/7/11
to django...@googlegroups.com
On Mon, 2011-11-07 at 04:28 -0500, Joey Espinosa wrote:
> Here's the Quick Start page: http://goo.gl/g5I7X

that is easy - how does one populate with data from django?
--
regards
Kenneth Gonsalves

skys...@gmail.com

unread,
Nov 7, 2011, 11:36:33 AM11/7/11
to django...@googlegroups.com, kenneth gonsalves
On 2011年11月07日 18:16, kenneth gonsalves wrote:
> On Mon, 2011-11-07 at 04:28 -0500, Joey Espinosa wrote:
>> Here's the Quick Start page: http://goo.gl/g5I7X
> that is easy - how does one populate with data from django?
do you know how to populate with data with other develop language??

kenneth gonsalves

unread,
Nov 7, 2011, 11:43:28 AM11/7/11
to django...@googlegroups.com

no - I was looking at gviz_api, which I got to work in python, but not
with django.

--
regards
Kenneth Gonsalves

Tim Sawyer

unread,
Nov 7, 2011, 12:09:14 PM11/7/11
to django...@googlegroups.com
Flot.

http://code.google.com/p/flot/

My docs about what I did:
http://drumcoder.co.uk/tags/flot/

Example (including zooming by slider):
http://brassbandresults.co.uk/bands/rothwell-temperance-band/

Enjoy,

Tim.

Andre Terra

unread,
Nov 7, 2011, 1:26:00 PM11/7/11
to django...@googlegroups.com
Pass serialized json as a template variable?

That's what I'm doing atm. But JKM has built an app to help reduce the need to write javascript [1]. I haven't used it myself, but it looks interesting and promising.


Cheers,
AT

[1] https://github.com/jacobian/django-googlecharts


--
regards
Kenneth Gonsalves

Yok Keen Hui

unread,
Nov 7, 2011, 2:22:47 PM11/7/11
to django...@googlegroups.com
You could try out cairoplot, it works for me in Django, just have to print the render as a picture to a url and reference it from there(looks nice too!)

Brad Montgomery

unread,
Nov 7, 2011, 3:05:35 PM11/7/11
to django...@googlegroups.com
+1 for Google Charts.


For small stuff (1 chart), I just render JavaScript in the <head> of my html templates. For more complex stuff, you could write a view that *just* renders JavaScript and include it via a script tag. Just make sure to serve it with MIME type "application/javascript"


Here's more info on generating Non-HTML content:
http://djangobook.com/en/2.0/chapter13/

Leotis buchanan

unread,
Nov 7, 2011, 4:23:14 PM11/7/11
to django...@googlegroups.com
You could also try processing.js


Regards
Leotis Buchanan
Co-Founder
Exterbox

mail....@gmail.com

unread,
Nov 7, 2011, 8:10:34 PM11/7/11
to Django users
Most times I just use css and percentwidth for simple bar charts.

On Nov 7, 10:23 am, Leotis buchanan <LeotisBucha...@exterbox.com>
wrote:

kenneth gonsalves

unread,
Nov 8, 2011, 2:18:59 AM11/8/11
to django...@googlegroups.com
On Mon, 2011-11-07 at 11:26 -0200, Andre Terra wrote:
> Pass serialized json as a template variable?
>
>

got it to work. I had passed the json, but had to turn autoescape off to
get it to work.
--
regards
Kenneth Gonsalves

skys...@gmail.com

unread,
Nov 8, 2011, 5:20:51 AM11/8/11
to django...@googlegroups.com
On 2011年11月07日 21:26, Andre Terra wrote:
Pass serialized json as a template variable?
yes of course, pupulate data from django is not special, it's a normal process just like other language. we can output json to the chart

Mario Gudelj

unread,
Nov 8, 2011, 10:16:38 AM11/8/11
to django...@googlegroups.com
Hey, I implemented a line chart and this is my code:

View:

def render_chart(request):
    months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
    month_values = [0,0,0,0,0,0,0,0,0,0,0,0]
    list_of_items = MyModel.objects.all()
    for item in list_of_items:
        if item.creation_date.strftime("%b") == months[item.creation_date.month - 1]:       
            month_values[item.creation_date.month - 1] = month_values[item.creation_date.month - 1] + 1

    d = {'user':request.user, 'months':months, 'month_values':month_values}
    return render_to_response('chart.html', d)

And this is the template:

script type="text/javascript">
    google.load("visualization", "1", {packages:["corechart"]});
    google.setOnLoadCallback(drawChart);
    function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Month');
        data.addColumn('number', 'bookings');
        data.addRows(12);
        {% for month in months %}
           
        data.setValue({{forloop.counter0}}, 0, '{{month}}');
        {% for value in month_values %}   
        data.setValue({{forloop.counter0}}, 1, {{value}});
            {%endfor%}
        {%endfor%}   
        var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
        chart.draw(data, {width: 760, height: 380, title: 'Stats'});
      }
</script

I'm a Django/Python beginner, but the above works for me and it plots the number of items per month, where the Y-axis is the number of items and X-axis is the month names.

I hope that helps!

kenneth gonsalves

unread,
Nov 8, 2011, 10:28:11 AM11/8/11
to django...@googlegroups.com
On Tue, 2011-11-08 at 21:16 +1100, Mario Gudelj wrote:
> I'm a Django/Python beginner, but the above works for me and it plots
> the number of items per month, where the Y-axis is the number of items
> and X-axis is the month names.

I found it faster and more efficient to generate the DataTable using
google's gviz_api
--
regards
Kenneth Gonsalves

Venkatraman S

unread,
Nov 8, 2011, 10:52:20 AM11/8/11
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages