Esempio n. 1
0
 def generateGraphs(self):
     # time taken
     chart = GroupedVerticalBarChart(len(self.index) * 10, len(self.index) * 10, x_range=(0, len(self.index)))
     chart.set_bar_width(10)
     chart.set_colours(["00ff00", "ff0000"])
     chart.add_data(self.index)
     chart.add_data(self.times)
     chart.download("vanilla-times.png")
Esempio n. 2
0
    def draw_overall(self,data,cl_list,title,band,max_y):
        self.init()
        chart = GroupedVerticalBarChart(1000,300,
                                        y_range=(0,max_y))


        for i in range(0,len(data)) :
            chart.add_data(data[i])

        chart.set_bar_width(18)
        chart.set_colours(['76A4FB', '224499','208020', '80C65A','FF0000'])

        chart.set_legend(cl_list)

        index=chart.set_axis_labels(Axis.BOTTOM, scenario_implemented)
        chart.set_axis_range(Axis.LEFT,0,max_y)
        chart.set_axis_style(index, colour='000000', \
                font_size= 6)

        chart.set_grid(0,5, 5, 5)
        IMG_DIR = os.path.join("serv2.icerasemi.com", "eng", "nsait", "img\\")
        IMG_DIR = 'serv2.icerasemi.com\eng\nsait\img\\'
        #dir = '\\serv2.nvidia.com\eng\nsait\img'
        dir = 'chart\\'
        chart.download(dir+title+str(band)+'.jpeg')
#!/usr/bin/python

import sys
import os
from pygooglechart import GroupedVerticalBarChart, Axis

datafile = sys.argv[1]
commitsfile = open(datafile, 'r')
name = os.path.basename(datafile)

data_array = []
legend_array = []

chart = GroupedVerticalBarChart(400, 200,
                                y_range=(0, 40))

#chart.set_bar_width(25)
#chart.set_bar_width(25)

for line in commitsfile:
    (legend, data) = line.split(' ')
    data_array.append(int(data.strip()))
    legend_array.append(legend)

print data_array
print legend_array

chart.add_data(data_array)
chart.set_axis_labels('x', legend_array)
chart.set_axis_labels('y', range(0,50,10))
def PrintAverageCharts(dataviews):
    # another chart that shows the deviation from the average over the week, as a bar chart
    print '<table frame="border">'
    ncols = 3
    print '<tr><td colspan="%d" align="center" style="font-family:Arial;">Averaged Pollutants per day of week</td></tr>' % ncols
    icharts = 0
    for title, view in dataviews:
        weekchart = dict(
            [d, dict([k, []] for k in view.keys())] for d in range(7)
        )  # for each day of the week, and for each data type an empty list

        # for each dataset in this view, put datapoint into the list of the week day
        for k in view:
            data = view[k]
            for iday in range(len(data)):
                weekchart[(iday + firstweekday) % 7][k].append(data[iday])

        # bar chart of averages per day
        datasets = []
        max_y = None
        for k in view:
            data = [0. for i in range(7)]
            for d in weekchart:
                data[d] = sum(weekchart[d][k]) / len(weekchart[d][k])
            datasets.append(data)
            max_y = max(max_y, max(data))

        # bar chart
        c = GroupedVerticalBarChart(400, 250, y_range=[0, max_y])
        c.set_bar_width(20 / len(datasets))
        c.set_bar_spacing(0)
        if len(datasets) > 1:
            c.set_legend([k[0] for k in view.keys()])

        # Set the line colours
        c.set_colours(['0000FF', 'FF0000'])

        for data in datasets:
            c.add_data(data)
        # y axis labels
        if max_y > 30:
            left_axis = range(0, int(max_y) + 1, 5)
        elif max_y > 10:
            left_axis = range(0, int(max_y) + 1, 1)
        elif max_y > 5:
            left_axis = []
            v = 0.
            while v < max_y + 0.5:
                left_axis.append(v)
                v += 0.5
        else:
            left_axis = []
            v = 0.
            while v < max_y + 0.1:
                left_axis.append(v)
                v += 0.1

        left_axis[0] = ''  # no label at 0
        c.set_axis_labels(Axis.LEFT, left_axis)
        c.set_axis_labels(Axis.BOTTOM, [weekdays[d] for d in weekchart.keys()])
        if icharts % ncols == 0:
            print '%s<tr>' % (icharts > 0 and '</tr>' or '')
        print '<td><img src="%s&chtt=%s"></td>' % (c.get_url(), title)
        icharts += 1
    print '</tr></table>'
#!/usr/bin/python

import sys
import os
from pygooglechart import GroupedVerticalBarChart, Axis

datafile = sys.argv[1]
name = os.path.basename(datafile)

commitsfile = open(datafile, 'r')
data_array = []
legend_array = []

chart = GroupedVerticalBarChart(800, 350,
                                y_range=(0, 3000))

#chart.set_bar_width(25)
#chart.set_bar_width(25)

for line in commitsfile:
    (legend, data) = line.split(' ')
    data_array.append(int(data.strip()))
    legend_array.append(legend)

print data_array
print legend_array

chart.add_data(data_array)
chart.set_axis_labels('x', range(1,25))
chart.set_axis_labels('y', range(0, 3250, 250))
Esempio n. 6
0
def get_chart_url(data):
    chart = GroupedVerticalBarChart(800, 200, y_range=(0, max(data)))
    chart.set_bar_width(3) #should be calculated
    chart.set_bar_spacing(0)
    chart.set_colours(['4D89F9'])
    chart.add_data(data)
    return chart.get_url()
Esempio n. 7
0
 def get_url_bits(self, data_class=None):
     url_bits = GroupedVerticalBarChart.get_url_bits(self, data_class)
     url_bits.append('chbh=a')
     return url_bits
def PrintAverageCharts(dataviews):           
    # another chart that shows the deviation from the average over the week, as a bar chart
    print '<table frame="border">'
    ncols = 3
    print '<tr><td colspan="%d" align="center" style="font-family:Arial;">Averaged Pollutants per day of week</td></tr>' % ncols
    icharts = 0
    for title, view in dataviews:
        weekchart = dict([d, dict([k, []] for k in view.keys())] for d in range(7)) # for each day of the week, and for each data type an empty list
    
        # for each dataset in this view, put datapoint into the list of the week day
        for k in view:
            data = view[k]
            for iday in range(len(data)):
                weekchart[(iday + firstweekday) % 7][k].append(data[iday])
    
        # bar chart of averages per day
        datasets = [ ]    
        max_y = None
        for k in view:
            data = [0. for i in range(7)]
            for d in weekchart:
                data[d] = sum(weekchart[d][k]) / len(weekchart[d][k])
            datasets.append(data)        
            max_y = max(max_y, max(data))
                
        # bar chart
        c = GroupedVerticalBarChart(400, 250, y_range=[0, max_y])
        c.set_bar_width(20/len(datasets))
        c.set_bar_spacing(0)
        if len(datasets) > 1:
            c.set_legend([k[0] for k in view.keys()])
        
        # Set the line colours
        c.set_colours(['0000FF', 'FF0000'])
    
        for data in datasets:
            c.add_data(data)
        # y axis labels
        if max_y > 30:
            left_axis = range(0, int(max_y) + 1, 5)
        elif max_y > 10:
            left_axis = range(0, int(max_y) + 1, 1)
        elif max_y > 5:
            left_axis = [ ]
            v = 0.
            while v < max_y + 0.5:
                left_axis.append(v)
                v += 0.5
        else:
            left_axis = [ ]
            v = 0.
            while v < max_y + 0.1:
                left_axis.append(v)
                v += 0.1

        left_axis[0] = '' # no label at 0
        c.set_axis_labels(Axis.LEFT, left_axis)
        c.set_axis_labels(Axis.BOTTOM, [weekdays[d] for d in weekchart.keys()])
        if icharts % ncols == 0:
            print '%s<tr>' % (icharts > 0 and '</tr>' or '')
        print '<td><img src="%s&chtt=%s"></td>' % (c.get_url(), title)
        icharts += 1
    print '</tr></table>'  
Esempio n. 9
0
def animalChanges(stats):


    for creature in ['rabbit', 'wolf']:
        chart = GroupedVerticalBarChart(600, 300)

        WYborn = []
        WYage = []
        WYstarv = []
        WYeaten = []
        WX = []
        for t in sorted(stats[creature].keys()):
            WX.append(t)
            born, age, starv, eaten = 0, 0, 0, 0
            for event in stats[creature][t]['event']:
                if event == LiveLog.BIRTH:
                    born += 1
                elif event == LiveLog.AGE:
                    age += 1
                elif event == LiveLog.STARV:
                    starv += 1
                elif event == LiveLog.EATEN:
                    eaten += 1
            WYborn.append(born)
            WYage.append(age)
            WYstarv.append(starv)
            WYeaten.append(eaten)

          #  print born, creature, str(stats[creature][t]['event'])

        chart.set_bar_width(4)
        chart.set_bar_spacing(1)
        chart.set_group_spacing(20)

        chart.set_title("Population changes/generation: / %s" % (creature))
        chart.add_data(WYborn)
        chart.add_data(WYage)
        chart.add_data(WYstarv)
        chart.add_data(WYeaten)
        chart.set_legend(['born', 'old age', 'starvation', 'eaten'])
        chart.set_colours(['00ff00', '000000', 'ff0000', 'ddbbbb'])
        chart.set_axis_labels(Axis.BOTTOM, range(0, max(WX) + 1, 5))

        chart.download('born-deaths-%s.png' % (creature))
Esempio n. 10
0
def __bar_graphic__(data,
                    legends,
                    axis_labels,
                    size,
                    steps,
                    type=StackedVerticalBarChart,
                    multiline=False):

    if multiline:
        max_values = []
        min_values = []
        for row in data:
            max_values.append(max(row))
            min_values.append(min(row))
        max_value = max(max_values)
        min_value = min(min_values)
    else:
        max_value = max(data)
        min_value = min(data)

    step = ((max_value * 1.05) - (min_value * 0.95)) / steps
    left_axis = range(int(min_value * 0.95), int(max_value * 1.05), int(step))
    left_axis[0] = ''

    if type == StackedHorizontalBarChart:
        graph = StackedHorizontalBarChart(size[0],
                                          size[1],
                                          x_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        graph.set_axis_labels(Axis.LEFT, axis_labels)
    elif type == StackedVerticalBarChart:
        graph = StackedVerticalBarChart(size[0],
                                        size[1],
                                        y_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        graph.set_axis_labels(Axis.BOTTOM, axis_labels)
    elif type == GroupedHorizontalBarChart:
        graph = GroupedHorizontalBarChart(size[0],
                                          size[1],
                                          x_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        graph.set_axis_labels(Axis.LEFT, axis_labels)
        graph.set_bar_spacing(5)
    elif type == GroupedVerticalBarChart:
        graph = GroupedVerticalBarChart(size[0],
                                        size[1],
                                        y_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        graph.set_axis_labels(Axis.BOTTOM, axis_labels)
        graph.set_bar_spacing(5)
    else:
        pass  #raise exception

    if multiline:
        for fila in data:
            graph.add_data(fila)
    else:
        graph.add_data(data)

    graph.set_colours(
        ['FFBC13', '22A410', 'E6EC23', '2B2133', 'BD0915', '3D43BD'])
    graph.set_bar_width(40)
    graph.set_legend(legends)
    graph.set_legend_position('b')

    return graph
Esempio n. 11
0
File: bar.py Progetto: thqbop/nuvola
def grouped_vertical():
    chart = GroupedVerticalBarChart(settings.width, settings.height,
                                    y_range=(0, 35))
    chart.set_bar_width(5)
    chart.set_colours(['00ff00', 'ff0000'])
    chart.add_data([1,2,3,4,5])
    chart.add_data([1,4,9,16,25])
    chart.download('bar-vertical-grouped.png')
Esempio n. 12
0
    def bargraph(self, days, bars, output, title=""):

        data = []
        min_count = 0
        max_count = 0
        date = lambda i: datetime.date.today() + datetime.timedelta(-days + i)

        for i in range(0, days + 1):
            count = bars[date(i)]
            max_count = max(count, max_count)
            min_count = min(count, min_count)
            data.append(count)
        # TOFIX: google chart API for negative numbers is too screwy, for now only >0
        min_count = max(min_count, 0)
        chart = GroupedVerticalBarChart(800,
                                        300,
                                        y_range=[min_count, max_count])
        chart.add_data(data)
        chart.set_bar_width(500 / days)
        # Set the line colour to blue
        chart.set_colours(['0000FF'])

        # Set the horizontal dotted lines
        chart.set_grid(0, 25, 5, 5)

        if days >= 30:
            fmt = "%d"
        else:
            fmt = "%d/%m"
        chart.set_axis_labels(Axis.BOTTOM, \
                              [date(i).strftime(fmt) for i in range(0,days)])

        # The Y axis labels contains 0 to 100 skipping every 25, but remove the
        # first number because it's obvious and gets in the way of the first X
        # label.
        delta = float(max_count - min_count) / 100
        skip = max(int(delta) / 5 * 100, 100)
        left_axis = range(0, max_count + 1, skip)
        left_axis[0] = ''
        chart.set_axis_labels(Axis.LEFT, left_axis)

        if len(title) > 0:
            chart.set_title(title % days)

        chart.download(output)
Esempio n. 13
0
        
    if fila['Año 2010 - Anual'] != '':
        filtrado1 = fila['Año 2010 - Anual'].replace('.', '')
        filtrado = filtrado1.replace(',', '.')
        salarios2010.append(filtrado)
        
    if fila['Año 2011 - Anual'] != '':
        filtrado1 = fila['Año 2011 - Anual'].replace('.', '')
        filtrado = filtrado1.replace(',', '.')
        salarios2011.append(filtrado)
    
fw = open('anuales.csv', 'w')
csvwriter = csv.writer(fw, delimiter=' ')
csvwriter.writerow(('Nivel;Salarios2009;Salarios2010;Salarios2011;Porcentaje2010;Porcentaje2011'))

chart = GroupedVerticalBarChart(600, 400, y_range=[0, 100])#iniciamos grafico
chart.set_bar_width(3)
chart.set_colours(['E01B4C', '421BE0', '1BE01B'])
chart.set_axis_labels(Axis.LEFT, ['0%', '50%', '100%'])

i = 0
for x in salarios2009:#generamos csv y chart
    csvwriter.writerow([nivel[i], ';'+salarios2009[i]+';', salarios2010[i]+';', salarios2011[i]+';', str(porcentaje(salarios2009[i], salarios2010[i]))+'%'+';', str(porcentaje(salarios2009[i], salarios2011[i]))+'%'])
    chart.add_data([100])
    chart.add_data([abs(porcentaje(salarios2009[i], salarios2010[i]))])
    chart.add_data([abs(porcentaje(salarios2009[i], salarios2011[i]))])
    i += 1

fw.close()
chart.download('sueldos_euskadi.png')
#!/usr/bin/python

import sys
import os
from pygooglechart import GroupedVerticalBarChart, Axis

datafile = sys.argv[1]

commitsfile = open(datafile, 'r')
data_array = []
legend_array = []

chart = GroupedVerticalBarChart(500, 300,
                                y_range=(0, 4500))

#chart.set_bar_width(25)
#chart.set_bar_width(25)

for line in commitsfile:
    (legend, data) = line.split(' ')
    data_array.append(int(data.strip()))
    legend_array.append(legend)

print data_array
print legend_array

chart.add_data(data_array)
chart.set_axis_labels('x', range(1,13))
chart.set_axis_labels('y', range(0, 5000, 500))

print chart.get_url()
Esempio n. 15
0
    def draw_scenario(self,dxp0,dxp1,cpu_dl,cpu_ul,ftp_dl,ftp_ul,cl_list,band,max_y,scen,branch):

        chart = GroupedVerticalBarChart(1000,300,
                                        y_range=(0,max_y))

        fixed_color =['ff154d', '7fff00' ,'0000ff','db7093','9f9f5f']

        color = []
        for i in range(0,len(cl_list)):
            if i < 5 :
                color.append(fixed_color[i])
            else:
                color.append(self.triplet(randint(100, 255), randint(100, 255), randint(100, 255)))

        chart.set_colours(color)

        #chart.set_colours(['76A4FB', '224499','208020', '80C65A','FF0000'])
        chart.set_legend(cl_list)
        chart.set_grid(0,5, 5, 5)
        #print scen
        if re.search('DL',scen) and re.search('UL',scen) :
            for j in range(0,len(scenario_implemented)):
                if scen == scenario_implemented[j] :
                    for i in range(0,len(cl_list)):
                        chart.add_data([dxp0[i][j],dxp1[i][j],cpu_dl[i][j],ftp_dl[i][j],cpu_ul[i][j],ftp_ul[i][j]])
                    index=chart.set_axis_labels(Axis.BOTTOM,["dxp0","dxp1","CPU_DL","FTP_DL","CPU_UL","FTP_UL"])
                    chart.set_bar_width(18)

        elif re.search('DL',scen):
            for j in range(0,len(scenario_implemented)):
                if scen == scenario_implemented[j] :
                    for i in range(0,len(cl_list)):
                        chart.add_data([dxp0[i][j],dxp1[i][j],cpu_dl[i][j],ftp_dl[i][j]])

                    index=chart.set_axis_labels(Axis.BOTTOM,["dxp0","dxp1","CPU_DL","FTP_DL"])
                    if(len(cl_list)<5):
                        chart.set_bar_width(36)
                    else:
                        chart.set_bar_width(18)

        elif re.search('UL',scen):
            for j in range(0,len(scenario_implemented)):
                if scen == scenario_implemented[j] :
                    for i in range(0,len(cl_list)):
                        chart.add_data([dxp0[i][j],dxp1[i][j],cpu_ul[i][j],ftp_ul[i][j]])

                    index=chart.set_axis_labels(Axis.BOTTOM,["dxp0","dxp1","CPU_UL","FTP_UL"])
                    if(len(cl_list)<5):
                        chart.set_bar_width(36)
                    else:
                        chart.set_bar_width(18)


        chart.set_axis_range(Axis.LEFT,0,max_y)
        chart.set_axis_style(index, colour='000000', \
                font_size= 12)

        chart_dir = 'chart\\'
        file = scen+"_"+"Band"+str(band)+"_"+branch+".jpeg"
        #print "src",chart_dir+file
        #print "dest",CHART_LOC+'\\\\'+file
        chart.download(chart_dir+file)
Esempio n. 16
0
def animalChangesInTime(stats):

    stats_t = {'rabbit': {}, 'wolf': {}}
    for creature in ['rabbit', 'wolf']:
        for t in stats[creature].keys():
            new_t = (t / 100) * 100 #zmniejszamy ilosc
            if new_t not in stats_t[creature]:
                stats_t[creature][new_t] = []
            stats_t[creature][new_t] += stats[creature][t]['event']    #tylko eventy
            print stats[creature][t]['event']


    for creature in ['rabbit', 'wolf']:
        chart = GroupedVerticalBarChart(600, 300)

        WYborn = []
        WYage = []
        WYstarv = []
        WYeaten = []
        WYcount = []
        WX = []
        count = 0
        for t in sorted(stats_t[creature].keys()):
            WX.append(t)
            print t
            print stats_t[creature][t]
            born, age, starv, eaten = 0, 0, 0, 0
            for event in stats_t[creature][t]:
                if event == LiveLog.BIRTH:
                    born += 1
                    count += 1
                elif event == LiveLog.AGE:
                    age += 1
                    count -= 1
                elif event == LiveLog.STARV:
                    starv += 1
                    count -= 1
                elif event == LiveLog.EATEN:
                    eaten += 1
                    count -= 1
            WYborn.append(born)
            WYage.append(age)
            WYstarv.append(starv)
            WYeaten.append(eaten)
            WYcount.append(count)


        print WYborn
        print WYcount
        print WYeaten

        chart.set_bar_width(4)
        chart.set_bar_spacing(1)
        chart.set_group_spacing(20)

        chart.set_title("Population changes/time: / %s" % (creature))
        chart.add_data(WYborn)
        chart.add_data(WYage)
        chart.add_data(WYstarv)
        chart.add_data(WYeaten)
        chart.add_data(WYcount)
        chart.auto_scale = True
        chart.set_legend(['born', 'old age', 'starvation', 'eaten', 'population size'])
        chart.set_colours(['00ff00', '000000', 'ff0000', 'ddbbbb', 'aa00ee'])
        chart.set_axis_labels(Axis.BOTTOM, range(0, max(WX) + 1, 100))

        chart.download('life-%s.png' % (creature))
Esempio n. 17
0
def grouped_vertical():
    chart = GroupedVerticalBarChart(settings['width'], settings['height'],
                                    y_range=(0, 35))
    chart.set_bar_width(5)
    chart.set_colours(['00ff00', 'ff0000'])
    chart.add_data([1,2,3,4,5])
    chart.add_data([1,4,9,16,25])
    chart.download('bar-vertical-grouped.png')
Esempio n. 18
0
        def bargraph(self,days,bars,output,title = ""):

                data = []
                min_count = 0
                max_count = 0
                date = lambda i:datetime.date.today() + datetime.timedelta(-days + i)

                for i in range(0,days+1):
                        count = bars[date(i)]
                        max_count = max(count,max_count)
                        min_count = min(count,min_count)
                        data.append(count)
                # TOFIX: google chart API for negative numbers is too screwy, for now only >0
                min_count = max (min_count,0)
                chart = GroupedVerticalBarChart(800,300,y_range=[min_count, max_count])
                chart.add_data(data)
                chart.set_bar_width(500 / days)
                # Set the line colour to blue
                chart.set_colours(['0000FF'])

                # Set the horizontal dotted lines
                chart.set_grid(0, 25, 5, 5)

                if days >= 30:
                        fmt = "%d"
                else:
                        fmt="%d/%m"
                chart.set_axis_labels(Axis.BOTTOM, \
                                      [date(i).strftime(fmt) for i in range(0,days)])

                # The Y axis labels contains 0 to 100 skipping every 25, but remove the
                # first number because it's obvious and gets in the way of the first X
                # label.
                delta = float(max_count-min_count) / 100
                skip = max(int(delta) / 5 * 100,100)
                left_axis = range(0, max_count + 1, skip)
                left_axis[0] = ''
                chart.set_axis_labels(Axis.LEFT, left_axis)

                if len(title) > 0:
                        chart.set_title(title % days)

                chart.download(output)
Esempio n. 19
0
    survey_id = row[0],
    choice_id = row[1],
    question_name = row[2],
    order = row[3],
    preceptor_id = row[4],
    preceptor_name = row[5],
    site_name = row[6],
  )
  conn.execute(ins)


preceptors = conn.execute(select([stats.c.preceptor_name, stats.c.site_name
  ]).group_by(stats.c.preceptor_name, stats.c.site_name))

for p in preceptors:
  chart = GroupedVerticalBarChart(500, 350,
    y_range=(0,5))
  chart.set_bar_width(7)
  chart.set_bar_spacing(0)
  chart.set_group_spacing(4)
  chart.set_colours(['ccffff', 'ffcc00', 'cc99ff'])
  chart.set_grid(0, 20, 5, 5)
  
  left_axis = range(0, 6, 1)
  left_axis[0] = '' #interfers with first x label
  chart.set_axis_labels(Axis.LEFT, left_axis)

  prec = p[0]
  site = p[1]
  questions = conn.execute(select([stats.c.question_name, stats.c.order, func.avg(stats.c.choice_id)],
      stats.c.preceptor_name == prec
    ).group_by(stats.c.order, stats.c.question_name, 
#!/usr/bin/python

import sys
import os
from pygooglechart import GroupedVerticalBarChart, Axis

datafile = sys.argv[1]
name = os.path.basename(datafile)

commitsfile = open(datafile, 'r')
data_array = []
legend_array = []

chart = GroupedVerticalBarChart(250, 300,
                                y_range=(0, 6000))

#chart.set_bar_width(25)
#chart.set_bar_width(25)

for line in commitsfile:
    (legend, data) = line.split(' ')
    data_array.append(int(data.strip()))
    legend_array.append(legend)

print data_array
print legend_array

chart.add_data(data_array)
chart.set_axis_labels('x', ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'])
chart.set_axis_labels('y', range(0, 6000, 500))
Esempio n. 21
0
def _bar_graph(data,
               legends,
               axis_labels,
               size,
               steps,
               type=StackedVerticalBarChart,
               multiline=False):

    if multiline:
        max_values = []
        min_values = []
        for row in data:
            max_values.append(max(row))
            min_values.append(min(row))
        max_value = max(max_values)
        min_value = min(min_values)
    else:
        max_value = max(data)
        min_value = min(data)

    #validando si hay datos para hacer grafico
    if max_value == 0:
        return None

    step = ((max_value * 1.05) - (min_value * 0.95)) / steps

    #validando en caso de el paso sea menor que uno y de cero en la conversion
    if step < 1:
        step = 1

    tope = int(round(max_value * 1.05))
    if tope < max_value:
        tope += 2
    else:
        tope += 1

    left_axis = range(int(round(min_value * 0.95)), tope, int(step))
    left_axis[0] = ''

    if type == StackedHorizontalBarChart:
        graph = StackedHorizontalBarChart(size[0],
                                          size[1],
                                          x_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        if axis_labels:
            graph.set_axis_labels(Axis.LEFT, axis_labels)
    elif type == StackedVerticalBarChart:
        graph = StackedVerticalBarChart(size[0],
                                        size[1],
                                        y_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        if axis_labels:
            graph.set_axis_labels(Axis.BOTTOM, axis_labels)
    elif type == GroupedHorizontalBarChart:
        graph = GroupedHorizontalBarChart(size[0],
                                          size[1],
                                          x_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        if axis_labels:
            graph.set_axis_labels(Axis.LEFT, axis_labels)
        graph.set_bar_spacing(5)
    elif type == GroupedVerticalBarChart:
        graph = GroupedVerticalBarChart(size[0],
                                        size[1],
                                        y_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        if axis_labels:
            graph.set_axis_labels(Axis.BOTTOM, axis_labels)
        graph.set_bar_spacing(5)
    else:
        pass  #raise exception

    if multiline:
        for fila in data:
            graph.add_data(fila)
    else:
        graph.add_data(data)

    graph.set_colours(
        ['FFBC13', '22A410', 'E6EC23', '2B2133', 'BD0915', '3D43BD'])
    graph.set_bar_width(44)
    graph.set_legend(legends)
    graph.set_legend_position('b')

    return graph
Esempio n. 22
0
def _get_bar_chart(width, height, data, background_color=None, colour=None):
    data = sorted([(int(k), v) for (k,v) in data.items()])
    
    min_ = min([x[1] for x in data])
    max_ = max([x[1] for x in data])
    
    chart = GroupedVerticalBarChart(width, height, 
                                    y_range=(min_, max_+30)) # add 30px for some extra space
    chart.add_data([x[1] for x in data])
    chart.set_axis_labels(pygooglechart.Axis.BOTTOM, [x[0] for x in data])
    interval = (max_ - min_) / 10
    if interval > 1000:
        interval = 5000
    elif interval > 500:
        interval = 1000
    elif interval > 100:
        interval = 500
    elif interval > 50:
        interval = 100
    else:
        interval = 50
    max_range = interval * (max_ / interval +1)
    chart.set_axis_labels(pygooglechart.Axis.LEFT, 
                          [str(x) for x in range(0, max_range, interval)])
    
    if background_color:
        chart.fill_solid(chart.BACKGROUND, background_color)
    if colour:
        chart.set_colours([colour])
    return chart.get_url()