Esempio n. 1
0
    def draw(self, style, size, output, labels=None):
        args = []
        colors = []
        for dataset in self.datasets:
            if isinstance(dataset, ChartData):
                args.append(dataset.data)
                colors.append(dataset.color)
            else:
                args.append(dataset)
                colors.append('black')

        # Default for X axis labels (numbered 1..n)
        if not labels:
            labels = [str(i) for i in range(1, len(args[0]) + 1)]

        # set colors for the data sets
        if colors:
            self.option(set_color=[int(Color(c)) for c in colors])

        # pass options to gdchart and render the chart
        gdchart.option(**self.options)

        # limit label length in order to workaround bugs in gdchart
        labels = [x[:32] for x in labels]
        gdchart.chart(*((style, size, output, labels) + tuple(args)))
Esempio n. 2
0
    def draw(self, style, size, output, labels=None):
        args = []
        colors = []
        for dataset in self.datasets:
            if isinstance(dataset, ChartData):
                args.append(dataset.data)
                colors.append(dataset.color)
            else:
                args.append(dataset)
                colors.append('black')

        # Default for X axis labels (numbered 1..n)
        if not labels:
            labels = [str(i) for i in range(1, len(args[0])+1)]

        # set colors for the data sets
        if colors:
            self.option(set_color=[int(Color(c)) for c in colors])

        # pass options to gdchart and render the chart
        gdchart.option(**self.options)

        # limit label length in order to workaround bugs in gdchart
        labels = [x[:32] for x in labels]
        gdchart.chart(*((style, size, output, labels) + tuple(args)))
 def draw(self):
     """Erstellt Chart als GIF. Gibt das GIF als string zurück."""
     # Put options into effect.
     gdchart.option(*(), **self.options)
     data = cStringIO.StringIO()
     args = (gdchart.GDC_3DBAR, self.size,
             data,
             self.names,
             self.frequencies)
     gdchart.chart(*args)
     return data.getvalue()
Esempio n. 4
0
class Chart:
    """ Wrapper for "gdchart".

        All GDC* constants are available as class attributes.
    """

    DEFAULTS = gdchart.option()

    def __init__(self):
        # Get a copy of the default options
        self.options = self.DEFAULTS.copy()
        self.datasets = []

        self.option(
            bg_color=0xffffff,
            line_color=0x000000,
        )

    def addData(self, data):
        self.datasets.append(data)

    def option(self, **args):
        # Save option values in the object's dictionary.
        self.options.update(args)

    def draw(self, style, size, output, labels=None):
        args = []
        colors = []
        for dataset in self.datasets:
            if isinstance(dataset, ChartData):
                args.append(dataset.data)
                colors.append(dataset.color)
            else:
                args.append(dataset)
                colors.append('black')

        # Default for X axis labels (numbered 1..n)
        if not labels:
            labels = [str(i) for i in range(1, len(args[0]) + 1)]

        # set colors for the data sets
        if colors:
            self.option(set_color=[int(Color(c)) for c in colors])

        # pass options to gdchart and render the chart
        gdchart.option(**self.options)

        # limit label length in order to workaround bugs in gdchart
        labels = [x[:32] for x in labels]
        gdchart.chart(*((style, size, output, labels) + tuple(args)))
 def __init__(self,
              title=None,
              xtitle=None,
              ytitle=None,
              names=[],
              frequencies=[]):
     logging.debug("Chart: t: %s x: %s y: %s names: %s freqs: %s" %
              (title,
              xtitle,
              ytitle,
              names,
              frequencies))
     # Get a copy of the default options
     self.options = gdchart.option().copy()
     self.size = (400, 500)
     self.option(set_color=(0x54A3DB, 0x307BAF))
     self.option(bg_color=0xFFFFFF, plot_color=0x0000cd, line_color=0x000000)
     self.option(title=title, xtitle=xtitle, ytitle=ytitle)
     self.names = names
     self.frequencies = frequencies