# charts

The component can display statistics related to data records (categorical variables). This can be used to show a single series or multiple series of data for comparative purposes and highlight specific regions or ranges on the chart to make it easier for users to interpret and analyze the data.This component is mostly used in [jig.default](https://docs.jigx.com/examples/readme/jig-types/jig_default) or [jig.list](https://docs.jigx.com/examples/readme/jig-types/jig_list).

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-cover data-type="image">Cover image</th></tr></thead><tbody><tr><td>Bar chart</td><td><a href="charts/bar-chart">Show more</a></td><td><a href="https://1414514342-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHcPzbms3kZejTmFd500V%2Fuploads%2F7IFVHPNOW5tOl2dPqlGe%2Fbar-chart.png?alt=media&#x26;token=4b0df1f6-ba5e-443d-8903-88f0d948dc25">bar-chart.png</a></td></tr><tr><td>Pie chart</td><td><a href="charts/pie-chart">Show more</a></td><td><a href="https://1414514342-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHcPzbms3kZejTmFd500V%2Fuploads%2FRYiLWbHKWXXNEuxkPcSv%2Fpie-chart.png?alt=media&#x26;token=c26a43c9-ea79-4e2a-a70d-eb122450879f">pie-chart.png</a></td></tr><tr><td>Line chart</td><td><a href="charts/line-chart">Show more</a></td><td><a href="https://1414514342-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHcPzbms3kZejTmFd500V%2Fuploads%2FpkXF7tY1Of38W5vGz5I6%2Fline-chart.png?alt=media&#x26;token=a85b4117-7fc5-4f18-bc3d-b8def7c08eeb">line-chart.png</a></td></tr><tr><td>Bar charts -plotbands</td><td><a href="charts/bar-chart">Show more</a></td><td><a href="https://1414514342-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHcPzbms3kZejTmFd500V%2Fuploads%2FEJEB8LtIc11KHhceudvH%2Fcharts-bar-plotbands-s.png?alt=media&#x26;token=3fe9e7f0-b3b4-4af3-8e31-c529712d2fa5">charts-bar-plotbands-s.png</a></td></tr><tr><td>Line charts -plotbands</td><td><a href="charts/line-chart">Show more</a></td><td><a href="https://1414514342-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHcPzbms3kZejTmFd500V%2Fuploads%2FiiQYETYIVhjwi8hSmgI4%2FCharts-Line-plotbands-s.png?alt=media&#x26;token=43dcfa67-9294-4c5a-b9de-ff4353764385">Charts-Line-plotbands-s.png</a></td></tr></tbody></table>

## Understanding chart data

Chart data is structured in a way that makes it easy to display. To understand how to create the YAML for a chart in Jigx Builder let's look at the data in various formats and how you can use the data in Jigx.

* Let's start with the financial data per quarter for three years from a **Microsoft Excel** table, as shown below:

<figure><img src="https://1414514342-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHcPzbms3kZejTmFd500V%2Fuploads%2Fa49BSSFJ0x2FtQgcicrX%2FC-ExcelData.png?alt=media&#x26;token=e82a3144-3771-42cf-981d-218c6d32cad7" alt="Excel data table" width="375"><figcaption><p>Excel data table</p></figcaption></figure>

* Next we map out the same data in Jigx [Dynamic Data](https://docs.jigx.com/building-apps-with-jigx/data/data-providers/dynamic-data) in[Jigx Management](https://docs.jigx.com/administration/solutions/data). Notice that the data is exactly the same as the Excel data.

<figure><img src="https://1414514342-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHcPzbms3kZejTmFd500V%2Fuploads%2FELcbOUi7B7DKZgZhTyRL%2FC-DD-data.png?alt=media&#x26;token=3498757d-bc6b-412a-a0b2-d8f72caaa83e" alt=""><figcaption></figcaption></figure>

* The same data can also exist in a **JSON** file. Using the *Download* button at the top-right of the Data-finance-data table shown above will download the data into a JSON file. The JSON is shown below.

<figure><img src="https://1414514342-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHcPzbms3kZejTmFd500V%2Fuploads%2FEmXeuSseO0M6d18OWkHy%2FC-JSON.png?alt=media&#x26;token=ea4473da-6c34-40b4-a857-a4a391badbb0" alt="JSON data" width="355"><figcaption><p>JSON data</p></figcaption></figure>

## Using the data in YAML

Now that you have your data you can convert it into the YAML needed for the charts. The data can be used as a static datasource or a dynamic datasource.

### YAML - Static data

Using the *finance-data.json* it was easy to convert the data into YAML as shown below.

{% code title="static-data" %}

```yaml
datasources:
  finance:
    type: datasource.static
    options:
      data:
        - Q1: 34000
          Q2: 22000
          Q3: 40000
          Q4: 51000
          Year: "2021"
        - Q1: 12000
          Q2: 48000
          Q3: 36000
          Q4: 12000
          Year: "2020"
        - Q1: 25000
          Q2: 32000
          Q3: 45000
          Q4: 86000
          Year: "2019"
```

{% endcode %}

### YAML - Dynamic Data

In Jigx you can use the data from the dynamic data table, in this instance *data-Finance-data*, then create a file under datasource folder. Use the Dynamic data provider that references the finance-data table with a query selecting the data you want to use, quarters and year in this example.

{% code title="dynamic-data" %}

```yaml
type: datasource.sqlite
options:
  provider: DATA_PROVIDER_DYNAMIC

  entities:
    - default/finance-data

  query: |
    SELECT
      id,
      '$.Q1', 
      '$.Q2', 
      '$.Q3', 
      '$.Q4', 
      '$.Year' 
    FROM [default/finance-data]
```

{% endcode %}

### YAML - Chart

In the YAML for charts the following keys are used: - `yAxis` - `xAxis` - `categories` - `series`

In this example the *finance-data* would show as follows for each key.

<figure><img src="https://1414514342-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHcPzbms3kZejTmFd500V%2Fuploads%2FvojVXwQKOMkosIxDZcMf%2FC-YAMLKey.png?alt=media&#x26;token=ed4d4a92-b665-4c7b-a72a-d2d40f7a5f3e" alt="Chart YAML data described" width="338"><figcaption><p>Chart YAML data described</p></figcaption></figure>

Now it is possible to create charts in YAML with the exact same data, for example a bar and line chart with the finance-data in the above YAML keys is shown below. Notice in the YAML below that the same YAML is used for both the bar and line chart.

{% code title="Bar-chart" %}

```yaml
children:
  # select the BAR-CHART component and configure the x-axis and y-axis
  - type: component.bar-chart
    options:
      chart:
        height: 250
      legend:
        isHidden: false

      yAxis:
        max: 90000
        min: 0
        labels:
          format:
            currency: USD
            numberStyle: currency
            compactDisplay: short
            notation: compact
        tickAmount: 8

      xAxis:
        categories: =@ctx.datasources.finance-data-dd.Year

      series:
        - data: =@ctx.datasources.finance-data-dd.Q1
          name: Q1
          color: color2

        - data: =@ctx.datasources.finance-data-dd.Q2
          name: Q2
          color: color3

        - data: =@ctx.datasources.finance-data-dd.Q3
          name: Q3
          color: color4

        - data: =@ctx.datasources.finance-data-dd.Q4
          name: Q4
          color: color5
```

{% endcode %}

{% code title="Line-chart" %}

```yaml
children:
  # select the LINE-CHART component and configure the x-axis and y-axis
  - type: component.line-chart
    options:
      chart:
        height: 250
      legend:
        isHidden: false

      yAxis:
        max: 90000
        min: 0
        labels:
          format:
            currency: USD
            numberStyle: currency
            compactDisplay: short
            notation: compact
        tickAmount: 8

      xAxis:
        categories: =@ctx.datasources.multi.Year

      series:
        - data: =@ctx.datasources.multi.Q1
          name: Q1
          color: color2

        - data: =@ctx.datasources.multi.Q2
          name: Q2
          color: color3

        - data: =@ctx.datasources.multi.Q3
          name: Q3
          color: color4

        - data: =@ctx.datasources.multi.Q4
          name: Q4
          color: color5
```

{% endcode %}

{% columns %}
{% column %}
The `component.bar-chart` in the Jigx App using the finance- data.
{% endcolumn %}

{% column %}

<figure><img src="https://1414514342-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHcPzbms3kZejTmFd500V%2Fuploads%2F3e7i7KjhFGqctfb9DOKd%2FC-BarMultiExplained.png?alt=media&#x26;token=8a2ad4b0-5197-42fe-af91-78205d57d5ae" alt="" width="188"><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

{% columns %}
{% column %}
The `component.line-chart` in the Jigx App using the finance- data.
{% endcolumn %}

{% column %}

<figure><img src="https://1414514342-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHcPzbms3kZejTmFd500V%2Fuploads%2FPJax6gKuSi56URphi2PV%2FC-LineExample.png?alt=media&#x26;token=4d57f03c-d837-4082-a247-a089fe15a560" alt="Line chart in Jigx" width="375"><figcaption><p>Line chart in Jigx</p></figcaption></figure>
{% endcolumn %}
{% endcolumns %}
