7
7
ROOT = os.path.dirname(os.path.abspath(__file__))
8
8
sys.path.insert(0, os.path.join(ROOT, '..'))
10
from pygooglechart import Chart
11
10
from pygooglechart import SimpleLineChart
12
11
from pygooglechart import XYLineChart
13
from pygooglechart import SparkLineChart
14
from pygooglechart import Axis
19
16
def simple_random():
20
chart = SimpleLineChart(settings.width, settings.height, y_range=(0, 100))
17
chart = SimpleLineChart(settings.width, settings.height)
21
18
chart.add_data(helper.random_data())
22
19
chart.download('line-simple-random.png')
25
chart = XYLineChart(settings.width, settings.height,
26
x_range=(0, 100), y_range=(0, 100))
22
chart = XYLineChart(settings.width, settings.height)
27
23
chart.add_data(helper.random_data())
28
24
chart.add_data(helper.random_data())
29
25
chart.download('line-xy-random.png')
32
chart = XYLineChart(settings.width, settings.height,
33
x_range=(0, 100), y_range=(0, 100))
34
chart.add_data([10, 90, 90, 10, 10])
35
chart.add_data([10, 10, 90, 90, 10])
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])
36
31
chart.download('line-xy-rect.png')
39
chart = XYLineChart(settings.width, settings.height,
40
x_range=(0, 100), y_range=(0, 100))
34
chart = XYLineChart(settings.width, settings.height)
53
47
chart.add_data(ylist)
54
48
chart.download('line-xy-circle.png')
57
chart = SparkLineChart(settings.width, settings.height)
58
chart.add_data(helper.random_data())
59
chart.download('line-sparkline.png')
63
# Set the vertical range from 0 to 50
65
chart = SimpleLineChart(200, 125, y_range=[0, max_y])
67
# First value is the highest Y value. Two of them are needed to be
69
chart.add_data([max_y] * 2)
72
chart.add_data([28, 30, 31, 33, 35, 36, 42, 48, 43, 37, 32, 24, 28])
73
chart.add_data([16, 18, 18, 21, 23, 23, 29, 36, 31, 25, 20, 12, 17])
74
chart.add_data([7, 9, 9, 12, 14, 14, 20, 27, 21, 15, 10, 3, 7])
76
# Last value is the lowest in the Y axis.
77
chart.add_data([0] * 2)
80
chart.set_colours(['000000'] * 5)
83
# from the top to the first real data
84
chart.add_fill_range('76A4FB', 0, 1)
86
# Between the 3 data values
87
chart.add_fill_range('224499', 1, 2)
88
chart.add_fill_range('FF0000', 2, 3)
90
# from the last real data to the
91
chart.add_fill_range('80C65A', 3, 4)
94
chart.set_axis_labels(Axis.LEFT, ['', max_y / 2, max_y])
95
chart.set_axis_labels(Axis.BOTTOM, ['Sep', 'Oct', 'Nov', 'Dec'])
97
chart.download('line-fill.png')
101
# Set the vertical range from 0 to 100
104
# Chart size of 200x125 pixels and specifying the range for the Y axis
105
chart = SimpleLineChart(200, 125, y_range=[0, max_y])
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
115
# Set the line colour to blue
116
chart.set_colours(['0000FF'])
118
# Set the vertical stripes
119
chart.fill_linear_stripes(Chart.CHART, 0, 'CCCCCC', 0.2, 'FFFFFF', 0.2)
121
# Set the horizontal dotted lines
122
chart.set_grid(0, 25, 5, 5)
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
127
left_axis = range(0, max_y + 1, 25)
129
chart.set_axis_labels(Axis.LEFT, left_axis)
132
chart.set_axis_labels(Axis.BOTTOM, \
133
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'])
135
chart.download('line-stripes.png')
146
56
if __name__ == '__main__':