# Value

{% hint style="success" %}
This is the official documentation of the `forestadmin-agent-django` and `forestadmin-agent-flask` Python agents.
{% endhint %}

![Value Chart example](/files/vwB1rUMCY5dVN9S6FATw)

Value Charts display a single numerical value.

They can be added to a Dashboard using the `addChart` method on the `agent` object

```python
from forestadmin.datasource_toolkit.context.agent_context import AgentCustomizationContext
from forestadmin.datasource_toolkit.decorators.chart.result_builder import ResultBuilder
from forestadmin.datasource_toolkit.interfaces.chart import Chart
from forestadmin.datasource_toolkit.interfaces.query.aggregation import Aggregation
from forestadmin.datasource_toolkit.interfaces.query.filter.unpaginated import Filter
from forestadmin.datasource_toolkit.interfaces.query.condition_tree.nodes.leaf import ConditionTreeLeaf

async def monthly_recuring_revenue_chart_fn(
    context: AgentCustomizationContext, result_builder: ResultBuilder
) -> Chart:
    aggregation = Aggregation({"field": "amount", "operation": "Count"})
    filter_ = Filter(
        {"condition_tree": ConditionTreeLeaf("status", "equal", "paid")}
    )
    rows = await context.datasource.get_collection("Payment").aggregate(
        context.caller, filter_, aggregation
    )
    return result_builder.value(rows[0]["value"])

agent.add_chart("monthlyRecuringRevenue", monthly_recuring_revenue_chart_fn)
```

Or to the "Analytics" Tab of a Collection using the `addChart` method on the `collection` object

```python
from forestadmin.datasource_toolkit.decorators.chart.collection_chart_context import CollectionChartContext
from forestadmin.datasource_toolkit.decorators.chart.result_builder import ResultBuilder
from forestadmin.datasource_toolkit.interfaces.chart import Chart
from forestadmin.datasource_toolkit.interfaces.query.aggregation import Aggregation
from forestadmin.datasource_toolkit.interfaces.query.filter.unpaginated import Filter
from forestadmin.datasource_toolkit.interfaces.query.condition_tree.nodes.leaf import ConditionTreeLeaf
from forestadmin.datasource_toolkit.interfaces.query.condition_tree.nodes.branch import ConditionTreeBranch

async def monthly_recuring_revenue_chart_fn(
    context: CollectionChartContext, result_builder: ResultBuilder
) -> Chart:
    aggregation = Aggregation({"field": "amount", "operation": "Sum"})
    filter_ = Filter(
        {
            "condition_tree": ConditionTreeBranch(
                "and",[
                    ConditionTreeLeaf(
                        "customer:id", "equal", await context.get_record_id()
                    ),
                    ConditionTreeLeaf("status", "equal", "paid"),
                ]
            )
        }
    )
    rows = await context.datasource.get_collection("Payment").aggregate(
        context.caller, filter_, aggregation
    )
    return result_builder.value(rows[0]["value"])

agent.customize_collection("Customer").add_chart(
    "monthlyRecuringRevenue", monthly_recuring_revenue_chart_fn
)
```

Optionally, an older value can be provided to the `resultBuilder` to display a growth percentage on the top right of the widget as in the following Chart display:

![Value chart with percentage example](/files/dqXSZdTeljsGI7P9lE3V)

```python
from forestadmin.datasource_toolkit.context.agent_context import AgentCustomizationContext
from forestadmin.datasource_toolkit.decorators.chart.result_builder import ResultBuilder
from forestadmin.datasource_toolkit.interfaces.chart import Chart

async def appointments_chart_fn(
    context: AgentCustomizationContext, result_builder: ResultBuilder
) -> Chart:
    # ...
    return result_builder.value(784, 760)

agent.add_chart("appointments", appointments_chart_fn)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.forestadmin.com/developer-guide-agents-python/agent-customization/charts/value.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
