1#!/usr/bin/python3.8
2#
3# Copyright 2008 Google Inc.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17from graphy.backends import google_chart_api
18from graphy import formatters
19from graphy import line_chart
20
21# Average monthly temperature
22sunnyvale = [49, 52, 55, 58, 62, 66, 68, 68, 66, 61, 54, 48, 49]
23chicago   = [25, 31, 39, 50, 60, 70, 75, 74, 66, 55, 42, 30, 25]
24
25print '<html>'
26print '<head><title>Yearly temperature in Chicago and Sunnyvale</title></head>'
27print '<body>'
28print '<h2>Yearly temperature in Chicago and Sunnyvale</h2>'
29chart = google_chart_api.LineChart()
30chart.AddLine(sunnyvale)
31chart.AddLine(chicago, pattern=line_chart.LineStyle.DASHED)
32print chart.display.Img(250, 100)
33
34print "<p>But that's hard to understand.  We need labels:</p>"
35chart.bottom.min = 0
36chart.bottom.max = 12
37chart.bottom.labels = ['Jan', 'Apr', 'Jul', 'Sep', 'Jan']
38chart.bottom.label_positions = [0, 3, 6, 9, 12]
39
40chart.left.min = 0
41chart.left.max = 80
42chart.left.labels = [10, 32, 50, 70]
43chart.left.label_positions = [10, 32, 50, 70]
44chart.data[0].label = 'Sunnyvale'
45chart.data[1].label = 'Chicago'
46chart.AddFormatter(formatters.InlineLegend)
47print chart.display.Img(250, 100)
48
49print '<p>A grid would be nice, too.</p>'
50
51chart.left.label_gridlines = True
52chart.bottom.label_gridlines = True
53print chart.display.Img(250, 100)
54
55print '</body>'
56print '</html>'
57