/+junk/pygooglechart-py3k

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/pygooglechart-py3k

« back to all changes in this revision

Viewing changes to examples/line.py

  • Committer: gak
  • Date: 2007-12-13 22:35:59 UTC
  • Revision ID: git-v1:a7ad1afe3f08b7de8b3a3cbdc7165d4f88ddbe92
version bump, added BadContentTypeException, added a few examples, added COPYING licence, code is more PEP8 friendly, download() checks for content type and raises on bad http codes, add_data returns the index of the dataset, Line doesn't allow being an instance.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
import os
 
4
import sys
 
5
import math
 
6
 
 
7
ROOT = os.path.dirname(os.path.abspath(__file__))
 
8
sys.path.insert(0, os.path.join(ROOT, '..'))
 
9
 
 
10
from pygooglechart import SimpleLineChart
 
11
from pygooglechart import XYLineChart
 
12
 
 
13
import settings
 
14
import helper
 
15
 
 
16
def simple_random():
 
17
    chart = SimpleLineChart(settings.width, settings.height)
 
18
    chart.add_data(helper.random_data())
 
19
    chart.download('line-simple-random.png')
 
20
 
 
21
def xy_random():
 
22
    chart = XYLineChart(settings.width, settings.height)
 
23
    chart.add_data(helper.random_data())
 
24
    chart.add_data(helper.random_data())
 
25
    chart.download('line-xy-random.png')
 
26
 
 
27
def xy_rect():
 
28
    chart = XYLineChart(settings.width, settings.height)
 
29
    chart.add_data([0, 100, 100, 0, 0])
 
30
    chart.add_data([0, 0, 100, 100, 0])
 
31
    chart.download('line-xy-rect.png')
 
32
 
 
33
def xy_circle():
 
34
    chart = XYLineChart(settings.width, settings.height)
 
35
    steps = 40
 
36
    xradius = 25
 
37
    yradius = 45
 
38
    xmid = 50
 
39
    ymid = 50
 
40
    xlist = []
 
41
    ylist = []
 
42
    for angle in xrange(0, steps + 1):
 
43
        angle = float(angle) / steps * math.pi * 2
 
44
        xlist.append(math.cos(angle) * xradius + xmid)
 
45
        ylist.append(math.sin(angle) * yradius + ymid)
 
46
    chart.add_data(xlist)
 
47
    chart.add_data(ylist)
 
48
    chart.download('line-xy-circle.png')
 
49
 
 
50
def main():
 
51
    simple_random()
 
52
    xy_random()
 
53
    xy_rect()
 
54
    xy_circle()
 
55
 
 
56
if __name__ == '__main__':
 
57
    main()
 
58