# Charts

{% hint style="success" %}
&#x20;This is the official documentation of Forest Admin Cloud.
{% endhint %}

Forest Admin is designed to provide you with the most flexible admin panel framework, allowing you to create charts with code to customize the visuals or the way data is retrieved.

{% hint style="info" %}
The following sections assume that you have correctly followed all the steps in the [Code Customization Getting Started](https://docs.forestadmin.com/cloud/code-customization/getting-started) guide.
{% endhint %}

### TL;DR <a href="#tl-dr" id="tl-dr"></a>

{% code title="src/index.ts" %}

```typescript
import type { Agent } from '@forestadmin/forest-cloud';
import { Schema } from '../typings';

export default function customizeAgent(agent: Agent<Schema>) {
  agent.addChart('monthlyRecurringRevenue', async (context, resultBuilder) => {
    // Your business logic to retrieve data here.
    return resultBuilder.value(10000000);
  });
}
```

{% endcode %}

### Implementing backend logic to retrieve data

Forest Admin allows you to code how the data powering any given chart. To do it, select the API tab in the Data section, and fill the API endpoint URL:

* If the chart is part of the global dashboard, then the URL should be `/forest/_charts/<chart_name>`
* If the chart is part of the Analytics tab of a specific collection, then the URL should be: `/forest/_charts/<collection_name>/<chart_name>`

<figure><img src="https://3681914749-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwfMeGo4DK4ZOTYwApD1a%2Fuploads%2FouWzrvuc4P0nWohg32Bl%2FScreenshot%202024-10-23%20at%2017.38.37.png?alt=media&#x26;token=c3532d0e-e488-4b0e-a72a-9430530f8f6a" alt="" width="375"><figcaption></figcaption></figure>

To make the code easier to read, all the code snippets below should be wrapped in the following code.

```typescript
import type { Agent } from '@forestadmin/forest-cloud';
import { Schema } from '../typings';

export default function customizeAgent(agent: Agent<Schema>) {
  // Insert the code snippet here.
}
```

To create a chart, you can use the `agent.addChart()` method.

Arguments:

* `name`<mark style="color:red;">\*</mark> *<mark style="color:green;">String</mark>*: The name of the chart.
* `handle`<mark style="color:red;">\*</mark> *<mark style="color:green;">Function</mark>*: A function that has the `context` and `resultBuilder` as arguments.

```typescript
agent.addChart('monthlyRecurringRevenue', async (context, resultBuilder) => {
  // Your business logic to retrieve data here.
  return resultBuilder.value(10000000);
});
```

{% hint style="info" %}
If you want to learn more about creating custom charts, you can find further explanations and examples [here](https://app.gitbook.com/s/9UN5oBJhgzLadOqi7jx6/agent-customization/charts#from-your-agent).
{% endhint %}

### Coding the visualization

If you need to create custom charts, you can also create  the right visuals using HTML, CSS, and JavaScript, you can make unique visualizations

<figure><img src="https://3681914749-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwfMeGo4DK4ZOTYwApD1a%2Fuploads%2FpwYtLOti2pIV2wT6waAe%2FScreenshot%202023-11-30%20at%2016.10.17.png?alt=media&#x26;token=5287fee8-7e6d-4fb1-9fd9-5694e5ec56d2" alt=""><figcaption></figcaption></figure>


---

# 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/cloud/code-customization/charts.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.
