[Tutor] Django SQLite data as Pie chart

Alan Gauld alan.gauld at yahoo.co.uk
Wed Aug 3 13:24:06 EDT 2016


On 03/08/16 12:25, Trevor H wrote:
> I am trying to create a website that could dynamically get data 
> ... but I'm not sure about how I would go plotting the data
> into a pie chart ...

There are basically three ways to tackle this.

1)  Create the chart as an image on the server and
    then upload it as a link from the HTML web page.
    You could include an image map to give a basic form
    of user interaction with the data. The image can
    be created using libraries such as Pillow or
    matplotlib or even the humble turtle.

2)  Create the chart as an SVG graphic on the server
   and upload to the browser as part of the HTML for
   display. You can associate click events with
   Javascript functions to provide interaction.

3) Make the raw data available on the server4 and
   get a Javascript function in the HTML to fetch it
   as needed and generate the imagery directly in the
   browsers DOM. (I believe there are JS libraries to
   assist in this but I've never used them)

They are arranged in order of simplicity. They are also
arranged in reverse order from the point of flexibility
and user interaction. As ever, it's a trade off.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list