示例#1
0
def Chart():
    key = 'year'  # or supplier
    aa = scraperwiki.datastore.retrieve({key: None})
    d = defaultdict(float)
    for a in aa:
        pp = a['data'][key]
        d[pp] += float(a['data']['amount'])

    years = sorted(d.keys())

    data = [int(d[key] / 1000) for key in years]
    xmax = int(max(data))

    chart = pygooglechart.StackedHorizontalBarChart(500,
                                                    325,
                                                    x_range=(0, xmax),
                                                    colours=["556600"])
    chart.set_title('Awards')
    chart.set_bar_width(12)

    chart.set_axis_labels(pygooglechart.Axis.LEFT, reversed(years))
    chart.set_axis_labels(pygooglechart.Axis.BOTTOM,
                          map(str, range(0, xmax, xmax / 5)))
    chart.add_data(data)
    graph_url = chart.get_url()
    print graph_url
    scraperwiki.metadata.save("chart", graph_url)
示例#2
0
def get_matchup_chart(username1, username2, rate):
    # 구글 차트
    chart = pgc.StackedHorizontalBarChart(320, 100, x_range=(0, 101))
    chart.set_bar_width(20)
    chart.set_colours(['e74c3c', 'f1c40f', '3498db'])
    chart.add_data(rate)
    chart.set_axis_labels(pgc.Axis.LEFT, [username2, "무승부", username1])
    chart.set_axis_labels(pgc.Axis.BOTTOM, range(0, 101, 20))

    return chart.get_url()
示例#3
0
def HorizontalBarChart(d, title):
    width = 425
    height = 10 * len(d) + 30
    xmax = max(d.values())
    chart = pygooglechart.StackedHorizontalBarChart(width,
                                                    height,
                                                    x_range=(0, xmax),
                                                    colours=["556600"])
    chart.set_legend([title])
    chart.set_bar_width(10)
    data = []
    axis = d.keys()
    axis.sort()
    for key in axis:
        data.append(d[key])
    chart.set_axis_labels(pygooglechart.Axis.LEFT, axis)
    chart.set_axis_labels(pygooglechart.Axis.BOTTOM,
                          map(str, range(0, xmax + 1, int(xmax / 10))))
    chart.add_data(data)
    return chart
示例#4
0
 def vertical_bar_chart(self, data, width=300):
     if not data:
         return ''
     # tranpose
     tdata = zip(*data)
     labels = list(tdata[0])
     values = tdata[1]
     bar_width = 10
     # add 5 for space between bars
     height = (bar_width + 5) * len(values)
     # was setting x_range but automatic behaviour seems better
     # x_range = (min(values), max(values))
     chart = pygooglechart.StackedHorizontalBarChart(width, height)
     chart.set_bar_width(bar_width)
     chart.set_colours(['cc0033'])
     chart.add_data(values)
     # have to reverse the labels for vertical
     labels.reverse()
     chart.set_axis_labels(pygooglechart.Axis.LEFT, labels)
     chart.set_axis_range(pygooglechart.Axis.BOTTOM, 0, max(values))
     chart.set_axis_range(pygooglechart.Axis.TOP, 0, max(values))
     url = chart.get_url()
     return url