# Time-based

{% hint style="success" %}
This is the official documentation of the `@forestadmin/agent` Node.js agent.
{% endhint %}

![Time-based Chart example](https://3861847666-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9UN5oBJhgzLadOqi7jx6%2Fuploads%2Fgit-blob-253eb57c97ada0f165298b7694909f94cca88898%2Fchart-time.png?alt=media)

Time-based charts are very similar to distribution charts, the only differences being that:

* An additional parameter tells the frontend if the dates should be displayed by `Day`, `Week`, `Month`, or `Year`,
* The returned data is an array of objects with `date` as a `Date` and `value` as a `Number`.

```javascript
agent.addChart('transactionVolume', async (context, resultBuilder) => {
  // [...]

  return resultBuilder.timeBased('Month', [
    { date: new Date('2017-02-01'), value: 636 },
    {
      date: new Date('2017-03-01'),
      value: 740,
    },
    {
      date: new Date('2017-04-01'),
      value: 648,
    },
    {
      date: new Date('2017-05-01'),
      value: 726,
    },
    // [...]
  ]);
});
```

If you want to add several lines to the same chart, you can use the `multipleTimeBased` method:

```javascript
agent.addChart('newUsersByProject', async (context, resultBuilder) => {
  // [...]

  return resultBuilder.multipleTimeBased(
    'Month',
    [
      new Date('2017-02-28'),
      new Date('2017-03-28'),
      new Date('2017-04-28'),
      new Date('2017-05-28'),
    ],
    [
      { label: 'Project 1', values: [636, 740, 648, 726] },
      { label: 'Project 2', values: [100, 200, 300, 400] },
    ],
  );
});
```


---

# 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-nodejs/agent-customization/charts/time.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.
