# Charts

Visualize your API data in a chart! This component allows you to generate data visualizations within your app using data from your backend tool.

![](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXpqEanvOhm8vMtIH8i%2Fuploads%2Fskb1ZNzuGSHcMW3j3pLd%2FScreen-Recording-2024-05-28-at-12.11.05.gif?alt=media\&token=eaabdaf4-8d41-42e9-8beb-2957c32c2647)

## 🏷 The Tags

Choose between **pie** and **bar** charts based on your data visualization needs. Select the format that best represents your information.

### :cake: Pie Chart

To create a pie chart, use:

```
[component:chart:pie]
```

![Bravorizing in Figma: Pie Chart](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXpqEanvOhm8vMtIH8i%2Fuploads%2FwBw3IUKBGTO8qiEIPsB3%2FCharts.jpg?alt=media\&token=49723fd2-becf-417d-bd71-149a989b26ee)

### :bar\_chart: Bar chart

To create a bar chart, use:

```
[component:chart:bar]
```

![Bravorizing in Figma: Bar chart](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXpqEanvOhm8vMtIH8i%2Fuploads%2FxEvGkFFF0EXn1ApK4vQB%2FCharts%20\(1\).jpg?alt=media\&token=8ceb1fdd-015e-4cc5-bc9e-ed631165b6bb)

## ⚒️ How to set it up

### 🎨 Design file setup

To add a chart component, create a rectangle element in your design file and add the tag <mark style="color:red;">`[component:chart:X]`</mark> to it, replacing <mark style="color:red;">`X`</mark> with one of the chart options described before. Place it inside a [container](https://docs.bravostudio.app/bravo-tags/containers).

{% hint style="info" %}
We recommend creating another rectangle element as a background inside the same container. This is shown in the screenshot below and also in the example design file.
{% endhint %}

You've got everything needed in your design file to create a chart component! Now, import it into Bravo and connect it with data.

### 🔌 Bind the charts to data

Depending on the [chart type](#the-tags) you're using, whether it's a pie or bar chart, you'll be able to bind different properties to it.

{% hint style="info" %}
A chart needs to be bound to a [**list data item**](https://docs.bravostudio.app/connect-api/set-up-api-requests/creating-an-api-collection/airtable/set-up-an-api-get-request-for-list-page-airtable). Each of the items in the list will be a data element in the chart, where each chart can contain as many data elements as needed.&#x20;

At the same time, each of the list data items obtained with the API request must contain individual data items that will be bound to the corresponding properties described below.
{% endhint %}

To get started, try our sample [Airtable base](#example-files). Duplicate it and use the [Airtable Wizard ](https://docs.bravostudio.app/connect-api/set-up-api-requests/api-wizard-importer/airtable-using-the-airtable-api-wizard)to create some API requests targeting the base. This way, you'll already have some data to bind to the chart component.

<figure><img src="https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXpqEanvOhm8vMtIH8i%2Fuploads%2FlIvYAZXr6x71cme4HDxv%2FCharts%20(2).jpg?alt=media&#x26;token=c6e63214-cdad-452a-9cb2-dde9c301c383" alt=""><figcaption><p>List data items selected</p></figcaption></figure>

<figure><img src="https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXpqEanvOhm8vMtIH8i%2Fuploads%2FYcz789fvkuMb8QShI0Ws%2FCharts%20(3).jpg?alt=media&#x26;token=a62ea891-f1a6-409d-b779-e5d6a98eebac" alt=""><figcaption></figcaption></figure>

#### 🍰 Pie charts

A pie chart contains the following properties:

* **Chart data: T**his property must be bound to a **list data item**, containing all the data elements of the pie chart. This property has three subproperties inside it:
  * **Value: T**he numeric value of a data element in the chart. In a pie chart, the percentage of each data element value, compared with the sum of values of all data elements, will be represented. This property needs to be bound to a **numeric data item**.
  * **Color**: The color of the pie portion corresponding to a data element. Needs to be bound to a data item containing the [HEX representation of a color](https://www.w3schools.com/colors/colors_hexadecimal.asp). (For instance, #FFFFFF for white). If this property is left unbound, a default color will be used.
  * **Name**: The tag name that will show together with the pie chart element.
* **Chart title**: Optionally, you can add a title to the chart. This is done by binding this property to a **single data item** containing the chart title.

The properties of the pie chart component are bound as shown below, in Bravo's Data Binding section.

![](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXpqEanvOhm8vMtIH8i%2Fuploads%2Fqeopsx0TEv3gdQFFZaBb%2FCharts%20\(4\).jpg?alt=media\&token=2f973159-04a5-4b30-8a4e-2d409e5c766b)

**📊 Bar charts**

A bar chart contains the following properties:

* **Chart data:** this property must be bound to a **list data item**, containing all the data elements of the bar chart. This property has three subproperties inside it:
  * **Value:** The numeric value of a data element in the chart. In a bar chart, each data element will be represented as a bar, and will have a height proportional to its value, and the value of the other data elements.
  * **Color**: The color of the bar corresponding to a data element. Needs to be bound to a data item containing the [HEX representation of a color](https://www.w3schools.com/colors/colors_hexadecimal.asp). (For instance, `#FFFFFF` for white). If this property is left unbound, a default color will be used.
  * **Name**: The tag name that will show together with the bar chart element.
* **Chart title**: Optionally, you can add a title to the chart. This is done by binding this property to a **single data item** containing the chart title.

The properties of the bar chart component are bound as shown below, in Bravo's Data Binding section.

![How to bind a Bar Chart with API data.](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXpqEanvOhm8vMtIH8i%2Fuploads%2FvJpWLTQUWicgOybV6vHG%2FCharts%20\(5\).jpg?alt=media\&token=f13767dd-d653-410d-94ea-1bded45bd1fd)

### 📲 Preview on Bravo Vision

Once you have imported the design file with the chart component **and** bound the data, you can see the charts on Bravo Vision!

## 💾 Example files

**Design file**

{% embed url="<https://www.figma.com/community/file/1047948152078509667/Bravo-Sample%3A-Charts>" %}

**Airtable base**

{% embed url="<https://airtable.com/shrpgYWOKMxiXMpqP>" %}

Your feedback is valuable to us. If you have any suggestions, questions, or issues, please don't hesitate to reach out to the [community](https://community.bravostudio.app/home).
