# Annotated Chart

This chart allows users to interactively change their data across a timeline. In the frontend, users can click inside the chart to display a modal with options to add a point or two to the timeline, as well as add an annotation for that point.

The chart requires a separate dataset for each series to plot, and it needs the y-field-name specified for each of them. All datasets must have the same name for the x-field and for the annotations field. The x-field values must be of type Date or convertible to it, the y-field must be integers, and the annotation field values must be strings.&#x20;

The modal that appears includes a slider to select the value that the user wants to add. This can be configured with the `slider_config` parameter, where the `max` value can be defined, and also the `defaultValue`. Labels can be added to the slider values using the `slider_marks` parameter.

## The Method To Use <a href="#the-method-to-use" id="the-method-to-use"></a>

The method is `s.plt.annotated_chart()`

It must contain the following input variables:

```python
data: Union[List[DataFrame], List[List[Dict]]]
order: int
x: str 
y: List[str] 
```

Accepts the following input variables as optional:

```python
annotations: str
rows_size: Optional[int]
cols_size: Optional[int]
padding: Optional[str]
title: Optional[str]
y_axis_name: Optional[str]
slider_config: Optional[Dict]
slider_marks: Optional[Dict]
```

## Examples <a href="#examples" id="examples"></a>

An example on how to use it would be:&#x20;

```python
data1 = [
    {'date': '2022-01-01', 'Value [1]': 3},
    {'date': '2022-03-01', 'Value [1]': 7, 'Annotation': 'Value [1] rapid increase'},
    {'date': '2022-04-01', 'Value [1]': 7},
    {'date': '2022-07-01', 'Value [1]': 8},
    {'date': '2022-08-01', 'Value [1]': 9},
    {'date': '2022-12-01', 'Value [1]': 5},
]
data2 = [
    {'date': '2021-12-31', 'Value [2]': 6},
    {'date': '2022-01-02', 'Value [2]': 9},
    {'date': '2022-02-01', 'Value [2]': 7},
    {'date': '2022-03-01', 'Value [2]': 8},
    {'date': '2022-04-01', 'Value [2]': 9},
    {'date': '2022-05-01', 'Value [2]': 7},
    {'date': '2022-06-01', 'Value [2]': 8, 'Annotation': 'Value [2] oscillation'},
    {'date': '2022-07-01', 'Value [2]': 9},
    {'date': '2022-08-01', 'Value [2]': 8},
]

s.plt.annotated_chart(
    order=0, x='date', y=['Value [1]', 'Value [2]'], annotations='Annotation',
    data=[data1, data2], slider_config={'max': 100, 'defaultValue': 50},
    slider_marks=[('Low', 15), ('Medium', 50), ('High', 85)]
)
```

<figure><img src="https://3782181538-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUlHTfmIZY46Z1EDfyGMz%2Fuploads%2Fd1DgnuwkkUTnVaKYMBpD%2FAnnotated%20Chart.png?alt=media&#x26;token=894def69-e2bb-44e6-8d54-5f52e199a6f7" alt=""><figcaption><p>Annotated chart with two datasets</p></figcaption></figure>

When clicking in the chart the modal appears like so:

<figure><img src="https://3782181538-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUlHTfmIZY46Z1EDfyGMz%2Fuploads%2FPGvn0TMY7DrqcYorTa8a%2Fimage.png?alt=media&#x26;token=31d22718-9c9d-4935-8ac7-c5703e6ceb67" alt=""><figcaption><p>Annotation modal</p></figcaption></figure>

It lets the user select a date range and the value of the point. Also it lets the user write an annotation in the bottom text field.

If we use the following values:&#x20;

<figure><img src="https://3782181538-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUlHTfmIZY46Z1EDfyGMz%2Fuploads%2F0PzBUIoiLccp92VKbSp6%2Fimage.png?alt=media&#x26;token=db1db513-5651-428d-9cbe-2666ca8fc012" alt=""><figcaption><p>Form ready to send</p></figcaption></figure>

The result in the chart is:

<figure><img src="https://3782181538-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUlHTfmIZY46Z1EDfyGMz%2Fuploads%2F8FDWoBqr6BCOHLHlQCox%2Fimage.png?alt=media&#x26;token=590fb5b1-1a8b-4fd8-93c4-ade97864bfed" alt=""><figcaption><p>Annotation added</p></figcaption></figure>
