'Helper function to download a Chart'

@staticmethod
def seriesChartDownload(r, **attr):

    from gluon.contenttype import contenttype
    filename = ('%s_chart.png' % r.record.name)
    response = current.response
    response.headers['Content-Type'] = contenttype('.png')
    response.headers['Content-disposition'] = ('attachment;    filename="%s"' % filename)
    chart_file = S3SurveySeriesModel.getChartName()
    cached = S3Chart.getCachedFile(chart_file)
    if cached:
        return cached
    output = {}
    get_vars = current.request.get_vars
    if ('labelQuestion' in get_vars):
        label_question = get_vars.labelQuestion
    if ('numericQuestion' in get_vars):
        numeric_question_list = get_vars.numericQuestion
        if (not isinstance(numeric_question_list, (list, tuple))):
            numeric_question_list = [numeric_question_list]
    if ((numeric_question_list != None) and (label_question != None)):
        S3SurveySeriesModel.drawChart(output, r.id, numeric_question_list, label_question, outputFormat='png')
    return output['chart']
