Beispiel #1
0
def barGraphData (responseBody, data, groups, title='Bar Graph', 
                  xBar='X Label', yBar='Y Label', 
                  colors=DefaultDictionary ('rgb(200,10,10)')):
    graph = BarGraph ()
    graph.setXLabel (xBar)
    graph.setYLabel (yBar)
    graph.setTitle (title)
    graph.setColors (colors)
    for rname, row in data:
        groupData = []
        for key in groups:
            try:
                value = row[key]
                groupData.append ((key, value))
            except KeyError:
                continue
        if len (groupData)> 0:
            graph.addGroup (rname, groupData)
    graph.finalize ()
    graph.save (responseBody)
Beispiel #2
0
 def bar_graph (self, filename, sort, groups, title = None, xlabel = None, ylabel = None, 
                settings = None, colors = None):
     from savage.graph import BarGraph
     #settings['horizontal'] = True
     graph = BarGraph (settings = settings)
     if xlabel:
         graph.setXLabel (xlabel)
     if ylabel:
         graph.setYLabel (ylabel)
     if title:
         graph.setTitle (title)
     if colors:
         graph.setColors (colors)
     for row in self:
         rname = row[sort]
         groupData = []
         for key in groups:
             try:
                 value = row[key]
                 groupData.append ((key, value))
             except KeyError:
                 continue
         if len (groupData)> 0:
             if len (groups) > 1:
                 graph.addGroup (rname, groupData)
             else:
                 graph.addBar (rname, groupData[0][1])
     graph.save (filename)