Ejemplo n.º 1
0
def pieChart(fd,
             width,
             height,
             title,
             data,
             labels,
             bgColor=None,
             labelColor='#000000',
             colorScheme=DEFAULT_COLOR):
    dataSet = [(name, [[0, value]]) for name, value in izip(labels, data)]
    axisLabels = [dict(v=i, label=label) for i, label in enumerate(labels)]

    options = Option(title=title,
                     titleFont='Times',
                     titleFontSize=24,
                     pieRadius=0.35,
                     legend=Option(hide=True),
                     colorScheme=colorScheme,
                     background=Option(baseColor=bgColor),
                     axis=Option(labelColor=labelColor,
                                 x=Option(ticks=axisLabels)))

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    chart = PieChart(surface, options)
    chart.addDataset(dataSet)
    chart.render()

    surface.write_to_png(fd)
Ejemplo n.º 2
0
Archivo: pie.py Proyecto: calston/tums
 def _updateTicks(self):
     """Evaluates pie ticks"""
     self.xticks = []
     if self.options.axis.x.ticks:
         lookup = dict([(slice.xval, slice) for slice in self.slices])
         for tick in self.options.axis.x.ticks:
             if not isinstance(tick, Option):
                 tick = Option(tick)
             slice = lookup[tick.v]
             label = tick.label or str(tick.v)
             if slice:
                 label += ' (%.1f%%)' % (slice.fraction * 100)
                 self.xticks.append((tick.v, label))
     else:
         for slice in self.slices:
             label = '%s (%.1f%%)' % (slice.xval, slice.fraction * 100)
             self.xticks.append((slice.xval, label))
Ejemplo n.º 3
0
 def _updateTicks(self):
     """Evaluates pie ticks"""
     self.xticks = []
     lookups = [key for key in self.slices.keys()]
     if self.options.axis.x.ticks:
         ticks = [tick['v'] for tick in self.options.axis.x.ticks]
         if frozenset(lookups) != frozenset(ticks):
             #TODO: Is there better option than ValueError?
             raise ValueError(u"Incompatible ticks")
         for tick in self.options.axis.x.ticks:
             if not isinstance(tick, Option):
                 tick = Option(tick)
             label = tick.label or str(tick.v)
             self.xticks.append((tick.v, label))
     else:
         for i in lookups:
             self.xticks.append((i, u"%s" % i))