/+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: 2008-08-25 08:03:22 UTC
  • Revision ID: git-v1:8d3e594fe5a5766de39cd4d7f93fc9e822960b1c
 - Added stripes and grid line chart to examples

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
ROOT = os.path.dirname(os.path.abspath(__file__))
8
8
sys.path.insert(0, os.path.join(ROOT, '..'))
9
9
 
 
10
from pygooglechart import Chart
10
11
from pygooglechart import SimpleLineChart
11
12
from pygooglechart import XYLineChart
12
13
from pygooglechart import SparkLineChart
59
60
 
60
61
def fill():
61
62
 
62
 
    # Set the vertical range to 0 to 50
 
63
    # Set the vertical range from 0 to 50
63
64
    max_y = 50
64
65
    chart = SimpleLineChart(200, 125, y_range=[0, max_y])
65
66
 
95
96
 
96
97
    chart.download('line-fill.png')
97
98
 
 
99
def stripes():
 
100
    
 
101
    # Set the vertical range from 0 to 100
 
102
    max_y = 100
 
103
 
 
104
    # Chart size of 200x125 pixels and specifying the range for the Y axis
 
105
    chart = SimpleLineChart(200, 125, y_range=[0, max_y])
 
106
 
 
107
    # Add the chart data
 
108
    data = [
 
109
        32, 34, 34, 32, 34, 34, 32, 32, 32, 34, 34, 32, 29, 29, 34, 34, 34, 37,
 
110
        37, 39, 42, 47, 50, 54, 57, 60, 60, 60, 60, 60, 60, 60, 62, 62, 60, 55,
 
111
        55, 52, 47, 44, 44, 40, 40, 37, 34, 34, 32, 32, 32, 31, 32
 
112
    ]
 
113
    chart.add_data(data)
 
114
    
 
115
    # Set the line colour to blue
 
116
    chart.set_colours(['0000FF'])
 
117
 
 
118
    # Set the vertical stripes
 
119
    chart.fill_linear_stripes(Chart.CHART, 0, 'CCCCCC', 0.2, 'FFFFFF', 0.2)
 
120
 
 
121
    # Set the horizonal dotted lines
 
122
    chart.set_grid(0, 25, 5, 5)
 
123
 
 
124
    # The Y axis labels contains 0 to 100 skipping every 25, but remove the
 
125
    # first number because it's obvious and gets in the way of the first X
 
126
    # label.
 
127
    left_axis = range(0, max_y + 1, 25)
 
128
    left_axis[0] = ''
 
129
    chart.set_axis_labels(Axis.LEFT, left_axis)
 
130
 
 
131
    # X axis labels
 
132
    chart.set_axis_labels(Axis.BOTTOM, \
 
133
        ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'])
 
134
 
 
135
    chart.download('line-stripes.png')
 
136
 
98
137
def main():
99
138
    simple_random()
100
139
    xy_random()
102
141
    xy_circle()
103
142
    sparklines()
104
143
    fill()
 
144
    stripes()
105
145
 
106
146
if __name__ == '__main__':
107
147
    main()