code: def run_pygal(data, options=[], format='svg'):
      
      import pygal
  
      chart_title = data.get('title', None)
      chart_type = data.get('type', '').lower()
      # Config options are pretty much proxied straight through from the JSON dict into the object
      config = pygal.Config()
      config_dict = data.get('config', {})
      for key in config_dict.keys():
          setattr(config, key, config_dict[key])
  
      if chart_type == 'bar':
          chart = pygal.HorizontalBar(config) if data.get('horizontal', False) else pygal.Bar(config)
      elif chart_type == 'line':
          chart = pygal.Line(config)
      elif chart_type == 'pie':
          ir=data.get('inner_radius', 0.0)
          hp=data.get('half_pie', False)
          chart = pygal.Pie(config, inner_radius=ir, half_pie=hp)
      else:
          print('undefined or unknown chart type')
  
      if chart is not None:
          chart.title = data.get('title', None)
          # Do labels (if present)
          label_data = data.get('x-labels', None)
          if isinstance(label_data, list):
              # use list
              chart.x_labels = label_data
          elif isinstance(label_data, dict):
              # use a range
              range_from = label_data.get('from', 0)
              range_to = label_data.get('to', 0)
              chart.x_labels = map(str, range(range_from, range_to))
          # insert data
          for data_set in data.get('data', []):
              title = data_set.get('title', None)
              values = data_set.get('values', None)
              chart.add(title, values)
          # now render
          result = chart.render_data_uri()
      else:
          result = None
      return result
docs: Runs pygal programs and returns image data