# Data Binding

The Kendo UI for Vue Chart supports the binding of its data series and category axis to arrays and Datasets of objects.

## Binding Series

This section provides information on the binding methods for the Chart series.

### Arrays of Values

The simplest form of data binding involves the supplying of each series with an array of values.

`Chart Data:`

```jsx
seriesData: [1, 2, 3, 5],
```

`Series binding:`

```jsx
<ChartSeriesItem :data-items="seriesData" />
```

[Demo Source](https://demos.telerik.com/kendo-vue-ui/charts/data-binding/values/source.txt)

### Arrays of Arrays

Some series require more than one value per point—for example, the Scatter (x and y) and Bubble (x, y, and size) series.

`Chart Data:`

```jsx
seriesData: [
  [1, 1, 10],
  [2, 2, 20],
  [3, 3, 30],
]
```

`Series binding:`

```jsx
<ChartSeriesItem :data-items="seriesData" :type="'bubble'" />
```

The following example demonstrates how to bind a Bubble series to an array of arrays.

[Demo Source](https://demos.telerik.com/kendo-vue-ui/charts/data-binding/arrays/source.txt)

### Objects

The Chart allows you to bind it to objects by specifying the fields you want to use—for the value, category, X value, Y value, and so on. This is the most commonly used type of binding as it allows you to use your model with minimal or no modification.

`Chart Data:`

```jsx
seriesData: [
  {
    product: "Chai",
    sales: 200,
  },
  {
    product: "Others",
    sales: 250,
  },
]
```

`Series binding:`

```jsx
<ChartSeriesItem
  :data-items="seriesData"
  :type="'column'"
  :field="'sales'"
  :category-field="'product'"
/>
```

The following example demonstrates how to configure a Column series with bound category text and a value.

[Demo Source](https://demos.telerik.com/kendo-vue-ui/charts/data-binding/objects/source.txt)

### Groups of Objects

Plotting a separate series for each unique category in a data set is often convenient. For example, a Line Chart for each product in a sales report. Usually, the exact number of categories is not known in advance.

The [Data Query](https://www.telerik.com/kendo-vue-ui-develop/components/dataquery) package offers a convenient [`groupBy`](https://www.telerik.com/kendo-vue-ui-develop/components/dataquery/api/groupby) method that you can use to split the records into groups. It takes the data and a [`GroupDescriptor`](https://www.telerik.com/kendo-vue-ui-develop/components/dataquery/api/groupdescriptor). The output is a [`GroupResult`](https://www.telerik.com/kendo-vue-ui-develop/components/dataquery/api/groupresult) that contains the groups and their items.

`Chart Data:`

```jsx
data: [
  {
    interval: 1,
    service: "Service 1",
    value: 5,
  },
  {
    interval: 2,
    service: "Service 1",
    value: 15,
  },
  {
    interval: 3,
    service: "Service 1",
    value: 10,
  },
  {
    interval: 1,
    service: "Service 2",
    value: 10,
  },
  {
    interval: 2,
    service: "Service 2",
    value: 5,
  },
  {
    interval: 3,
    service: "Service 2",
    value: 15,
  },
]
```

`Series binding:`

```jsx
<ChartSeriesItem
  v-for="(item, index) in series"
  :key="index"
  :data-items="item.items"
  :name="item.value"
  :field="'value'"
  :category-field="'interval'"
  :type="'line'"
/>
```

The following example demonstrates how to plot a Line Chart for each service.

[Demo Source](https://demos.telerik.com/kendo-vue-ui/charts/data-binding/group-objects/source.txt)

## Binding Categories

The category axis of Categorical Charts is a data-bound component like the series.

It supports the following basic approaches for providing the category list:

* [Arrays of labels](https://www.telerik.com/kendo-vue-ui-develop/components/charts/data-binding#arrays-of-labels)
* [Category fields](https://www.telerik.com/kendo-vue-ui-develop/components/charts/data-binding#category-fields)

> When you bind the Chart to dates, the category axis provides dedicated functions. For more information, refer to the section on [displaying time series](https://www.telerik.com/kendo-vue-ui-develop/components/charts/elements/axes#displaying-time-series).

### Arrays of Labels

The simplest form of data binding involves the supplying of an array of labels for the categories to the axis. The list will be displayed as is, without any modifications. Series data points are positioned in sequence along the axis.

> * The order of the categories has no relation to the order of the series data points.
> * The number of the categories has to be equal to the number of the data points in the series.
> * To preserve the order, the missing values in the series have to be represented by `null`.

`Chart Data:`

```jsx
seriesData: [20, 40, 45, 30, 50],
categories: ["Mon", "Tue", "Wed", "Thu", "Fri"],
```

`Series binding:`

```jsx
<ChartCategoryAxis>
  <ChartCategoryAxisItem :categories="categories" />
</ChartCategoryAxis>
<ChartSeries>
  <ChartSeriesItem :data-items="seriesData" />
</ChartSeries>
```

[Demo Source](https://demos.telerik.com/kendo-vue-ui/charts/data-binding/labels/source.txt)

### Category Fields

The [previous approach](https://www.telerik.com/kendo-vue-ui-develop/components/charts/data-binding#arrays-of-labels) is error-prone because of the necessity for you to maintain a category and a particular data order. To avoid this requirement, bind the categories to the same model object as the series. In this way, the series points and categories will always be matched automatically.

`Chart Data:`

```jsx
seriesData: [
  {
    product: "Chai",
    sales: 200,
  },
  {
    product: "Others",
    sales: 250,
  },
]
```

`Series binding:`

```jsx
<ChartSeriesItem
  :data-items="seriesData"
  :type="'column'"
  :field="'sales'"
  :category-field="'product'"
/>
```

[Demo Source](https://demos.telerik.com/kendo-vue-ui/charts/data-binding/category-field/source.txt)

### Handling Duplicate Categories

Binding to a category field makes it possible for two data points to have the same category—the following example demonstrates two values that are declared for `'Chai'`.

`Chart Data:`

```jsx
seriesData: [
  {
    product: "Chai",
    sales: 200,
  },
  {
    product: "Chai",
    sales: 100,
  },
  {
    product: "Others",
    sales: 250,
  },
]
```

`Series binding:`

```jsx
<ChartSeriesItem
  :data-items="seriesData"
  :type="'column'"
  :field="'sales'"
  :category-field="'product'"
/>
```

[Demo Source](https://demos.telerik.com/kendo-vue-ui/charts/data-binding/duplicates/source.txt)

In this case, the Chart takes the data points from the source data set and produces a new point by using an aggregate function.

By default, the [`aggregate`](https://www.telerik.com/kendo-vue-ui-develop/components/charts/api/chartseriesitemprops#aggregate) function returns the maximum value of the value fields. If the category contains only one point, it returns it without modification. Other aggregates, such as count and sum, produce their own value even if the category contains only one data point.

`Chart Data:`

```jsx
seriesData: [
  {
    product: "Chai",
    sales: 200,
  },
  {
    product: "Chai",
    sales: 100,
  },
  {
    product: "Others",
    sales: 250,
  },
]
```

`Series binding:`

```jsx
<ChartSeriesItem
  :data-items="seriesData"
  :type="'column'"
  :field="'sales'"
  :aggregate="'count'"
  :category-field="'product'"
/>
```

[Demo Source](https://demos.telerik.com/kendo-vue-ui/charts/data-binding/duplicates-aggregate/source.txt)

You can also define your own aggregate functions, as demonstrated in the following example

> When the category binding is in use, the aggregate function is executed for all unique categories.

`Chart Data:`

```jsx
seriesData: [
  {
    product: "Chai",
    sales: 200,
  },
  {
    product: "Chai",
    sales: 100,
  },
  {
    product: "Others",
    sales: 250,
  },
]
```

`Series binding:`

```jsx
<ChartSeriesItem
  :data-items="seriesData"
  :type="'column'"
  :field="'sales'"
  :aggregate="customAggregate"
  :category-field="'product'"
/>
```

`Custom aggregate definition:`

```jsx
customAggregate(values, series, dataItems, category) {
  return values.reduce((n, acc) => acc + n, 0);
}
```

[Demo Source](https://demos.telerik.com/kendo-vue-ui/charts/data-binding/duplicates-aggregate-custom/source.txt)

## Dynamic Data Updates

The Chart enables you to show dynamic data updates by changing the series [`data-items`](https://www.telerik.com/kendo-vue-ui-develop/components/charts/api/chartseriesitemprops#dataitems) at runtime to display points that are added, removed, or modified.

The following example demonstrates how to add, remove, and randomize data points in a [`line`](https://www.telerik.com/kendo-vue-ui-develop/components/charts/api/chartseriesitemprops#type) series of a Chart. Each button rebinds a new array to the [`data-items`](https://www.telerik.com/kendo-vue-ui-develop/components/charts/api/chartseriesitemprops#dataitems) prop of the [ChartSeriesItem](https://www.telerik.com/kendo-vue-ui-develop/components/charts/api/chartseriesitemprops).

[Demo Source](https://demos.telerik.com/kendo-vue-ui/charts/data-binding/data-operations/source.txt)

The [StockChart](https://www.telerik.com/kendo-vue-ui-develop/components/charts/api/stockchartprops) supports the same dynamic updates. The following example simulates a live feed by appending a new [`candlestick`](https://www.telerik.com/kendo-vue-ui-develop/components/charts/api/chartseriesitemprops#type) point every second while the **Play** control is active. Use the **Pause** control to stop the stream, inspect the current range through the [`ChartNavigator`](https://www.telerik.com/kendo-vue-ui-develop/components/charts/api/chartnavigatorprops), and resume whenever you need to continue receiving updates. The visible range stays fixed through the [ChartNavigatorSelect](https://www.telerik.com/kendo-vue-ui-develop/components/charts/api/chartnavigatorselectprops) [`from`](https://www.telerik.com/kendo-vue-ui-develop/components/charts/api/chartnavigatorselectprops#from) and [`to`](https://www.telerik.com/kendo-vue-ui-develop/components/charts/api/chartnavigatorselectprops#to) props.

[Demo Source](https://demos.telerik.com/kendo-vue-ui/charts/data-binding/stock-operations/source.txt)

## No Data Overlay

Use the [ChartNoDataOverlay](https://www.telerik.com/kendo-vue-ui-develop/components/charts/api/chartnodataoverlay) component when no series data is available. The Chart will display a No Data overlay with a message "No data available.". The message can be localized and is part of the Charts [Globalization - Messages](https://www.telerik.com/kendo-vue-ui-develop/components/charts/globalization#messages).

[Demo Source](https://demos.telerik.com/kendo-vue-ui/charts/data-binding/no-data-overlay/source.txt)

For further customization, add the custom content as `children` of the [ChartNoDataOverlay](https://www.telerik.com/kendo-vue-ui-develop/components/charts/api/chartnodataoverlay) component.

[Demo Source](https://demos.telerik.com/kendo-vue-ui/charts/data-binding/no-data-overlay-children/source.txt)

## Suggested Links

* [API Reference of the Chart](https://www.telerik.com/kendo-vue-ui-develop/components/charts/api)
* [Glossary](https://www.telerik.com/kendo-vue-ui-develop/components/charts/glossary)
