899
chart = PieChart2D(320, 200)
900
chart = ScatterChart(320, 200)
901
chart = SimpleLineChart(320, 200)
902
chart = GroupedVerticalBarChart(320, 200)
903
# chart = SplineRadarChart(500, 500)
904
# chart = MapChart(440, 220)
905
# chart = GoogleOMeterChart(440, 220, x_range=(0, 100))
906
sine_data = [math.sin(float(a) / math.pi) * 100 for a in xrange(100)]
907
random_data = [random.random() * 100 for a in xrange(100)]
908
random_data2 = [random.random() * 50 for a in xrange(100)]
909
# chart.set_bar_width(50)
910
# chart.set_bar_spacing(0)
911
chart.add_data(sine_data)
912
chart.add_data(random_data)
913
# chart.set_zero_line(1, .5)
914
# chart.add_data(random_data2)
915
# chart.set_line_style(0, thickness=5)
916
# chart.set_line_style(1, thickness=2, line_segment=10, blank_segment=5)
917
# chart.set_title('heloooo weeee')
918
# chart.set_legend(('sine wave', 'random * x'))
919
chart.set_colours(('ee2000', 'DDDDAA', 'fF03f2'))
920
# chart.fill_solid(Chart.ALPHA, '123456')
921
# chart.fill_linear_gradient(Chart.ALPHA, 20, '004070', 1, '300040', 0,
923
# chart.fill_linear_stripes(Chart.CHART, 20, '204070', .2, '300040', .2,
925
# axis_left_index = chart.set_axis_range(Axis.LEFT, 0, 10)
926
# axis_right_index = chart.set_axis_range(Axis.RIGHT, 5, 30)
927
# axis_bottom_index = chart.set_axis_labels(Axis.BOTTOM, [1, 25, 95])
928
# chart.set_axis_positions(axis_bottom_index, [1, 25, 95])
929
# chart.set_axis_style(axis_bottom_index, '003050', 15)
931
# chart.set_pie_labels(('apples', 'oranges', 'bananas'))
933
# chart.set_grid(10, 10)
934
# for a in xrange(0, 100, 10):
935
# chart.add_marker(1, a, 'a', 'AACA20', 10)
937
# chart.add_horizontal_range('00A020', .2, .5)
938
# chart.add_vertical_range('00c030', .2, .4)
940
# chart.add_fill_simple('303030A0')
942
# chart.set_codes(['AU', 'AT', 'US'])
943
# chart.add_data([1,2,3])
944
# chart.set_colours(('EEEEEE', '000000', '00FF00'))
946
# chart.add_data([50,75])
947
# chart.set_pie_labels(('apples', 'oranges'))
949
url = chart.get_url()
952
chart.download('test.png')
955
data = urllib.urlopen(chart.get_url()).read()
956
open('meh.png', 'wb').write(data)
957
os.system('eog meh.png')
960
if __name__ == '__main__':
912
class ChartGrammar(object):
914
def __init__(self, grammar):
915
self.grammar = grammar
916
self.chart = self.create_chart_instance()
919
def get_possible_chart_types():
921
for cls_name in globals():
922
if not cls_name.endswith('Chart'):
924
cls = globals()[cls_name]
925
# Check if it is an abstract class
928
except AbstractClassException:
931
possible_charts.append(cls_name[:-5])
932
return possible_charts
934
def create_chart_instance(self):
935
assert('w' in grammar) # width is required
936
assert('h' in grammar) # height is required
937
assert('type' in grammar) # type is required
938
types = ChartGrammar.get_possible_chart_types()
939
if grammar['type'] not in types:
940
raise UnknownChartType('%s is an unknown chart type. Possible '
941
'chart types are %s' % (grammar['type'], ','.join(types)))