Show Charts and graphs in Reports

Hi

I want to show graphs and charts base on my generated report like the graph below :

Charts

This is currently under review and will be merged soon

3 Likes

I understand , But I meant what is the python code make a charts from a script report

In the execute method, you need to return columns, data and chart

def execute(filters=None):
    data = get_data(params)
    columns = get_columns(params)
    chart = get_chart(params)
    return columns, data, None, chart

In the get_chart method (you can name it something else if you want to), organize your data and return your chart for the report. Here’s the get_chart code of a report that I did on V7:

def get_chart(columns, amount, qty, profit, percent):
    x_intervals = ['x'] + [d.get("label") for d in columns[3:]]
    amount_data, qty_data, profit_data, percent_data = [], [], [], []

    for p in columns[3:]:
        if amount:
            amount_data.append(amount[0].get(p.get("fieldname")))
        if qty:
            qty_data.append(qty[0].get(p.get("fieldname")))
        if profit:
            profit_data.append(profit[0].get(p.get("fieldname")))
        if percent:
            percent_data.append(amount[0].get(p.get("fieldname")))

    columns = [x_intervals]
    if amount_data:
        columns.append(["Peso Value"] + amount_data)
    if qty_data:
        columns.append(["Volume"] + qty_data)
    if profit_data:
        columns.append(["Profit"] + profit_data)
    if percent_data:
        columns.append(["Percent Increase/Decrease"] + amount_data)
    chart = {
        "data": {
            'x': 'x',
            'columns': columns
        }
    }

    chart["chart_type"] = "line"

    return chart
1 Like