# Angular Data Grid Chart Integration

Integrating charts within the [Angular Grid](https://www.telerik.com/kendo-angular-ui-develop/components/grid) provides a visual representation of the data, making trends, patterns, and outliers more clear compared to raw table data.

Use the [Kendo UI for Angular Chart Wizard](https://www.telerik.com/kendo-angular-ui-develop/components/chart-wizard) component to quickly create the desired chart using the Grid data.

The following example demonstrates how to launch the Chart Wizard from a [Context Menu](https://www.telerik.com/kendo-angular-ui-develop/components/grid/accessories/context-menu).

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/chart-integration/context-menu/source.txt)

## Generating Chart from Grid Selection

You can create charts from the Grid row and cell selection. Use one of the following methods to set up the [Chart Wizard](https://www.telerik.com/kendo-angular-ui-develop/components/chart-wizard) component:

* [Using Data-Binding Directive](https://www.telerik.com/kendo-angular-ui-develop/components/grid/integration-with-chart#using-data-binding-directives)—Reduce the repetitive boilerplate code when creating charts from the Grid data.
* [Using Grid Selected Keys](https://www.telerik.com/kendo-angular-ui-develop/components/grid/integration-with-chart#using-grid-selected-keys)—Create charts from the Grid `selectedKeys` property collection.

### Using Data-Binding Directives

To bind the Chart Wizard component and create charts based on the Grid selection:

1. Set the [`kendoGridBinding`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/databindingdirective) and [`kendoGridSelectBy`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/selectiondirective) directives of the Grid.

2. Apply the [`kendoChartWizardGridBinding`](https://www.telerik.com/kendo-angular-ui-develop/components/chart-wizard/api/chartwizardgridbindingdirective) directive and set the `chartWizardData` property.

   ```html
   <kendo-grid
       [kendoGridBinding]="data"
       kendoGridSelectBy="ID"
       [selectable]="selectionSettings"
       kendoChartWizardGridBinding
       [(chartWizardData)]="wizardData">
   </kendo-grid>
   ```

3. Set the [`data`](https://www.telerik.com/kendo-angular-ui-develop/components/chart-wizard/api/chartwizardcomponent#data) property of the Chart Wizard component to the `wizardData` array.

   ```html
   <kendo-chartwizard [data]="wizardData"></kendo-chartwizard>
   ```

The following example demonstrates the chart integration when using binding directives.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/chart-integration/binding-directive/source.txt)

### Using Grid Selected Keys

The Chart Wizard component expects data of type [`ChartWizardDataRow`](https://www.telerik.com/kendo-angular-ui-develop/components/chart-wizard/api/chartwizarddatarow). To map the `selectedKeys` array to the supported format, use the built-in [`getWizardDataFromGridSelection`](https://www.telerik.com/kendo-angular-ui-develop/components/chart-wizard/api/getwizarddatafromgridselection) method.

```ts
import { getWizardDataFromGridSelection } from '@progress/kendo-angular-chart-wizard';

@ViewChild('grid') public grid: GridComponent;
public data: any[] = sampleData;
public mySelection: { itemKey: any; columnKey: number }[] = [];
public selectionKey = 'ID';

public onSelectionChange(): void {
    this.wizardData = getWizardDataFromGridSelection({
        grid: this.grid,
        data: this.data,
        selectedKeys: this.mySelection,
        selectionKey: this.selectionKey,
    });
}
```

The following example demonstrates the `getWizardDataFromGridSelection` helper method in action.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/chart-integration/helper-methods/source.txt)

## Generating Chart from Custom Data

You can bind the [Chart Wizard](https://www.telerik.com/kendo-angular-ui-develop/components/chart-wizard) component without selecting any Grid rows or cells by providing a custom collection to the `selectedKeys` field of the [`getWizardDataFromGridSelection`](https://www.telerik.com/kendo-angular-ui-develop/components/chart-wizard/api/getwizarddatafromgridselection) helper method.

```ts
plotAllData(): void {
    this.wizardData = getWizardDataFromGridSelection({
        grid: this.grid,
        data: this.data,
        selectedKeys: this.data.map(item => item.ID),
        selectionKey: 'ID'
    });
}
```

The following example demonstrates how plot all data of the Grid.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/chart-integration/all-data/source.txt)

## Suggested Links

* [Chart Wizard Overview](https://www.telerik.com/kendo-angular-ui-develop/components/chart-wizard)
* [API Index of the Grid](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api)
* [API Index of the Chart Wizard](https://www.telerik.com/kendo-angular-ui-develop/components/chart-wizard/api)
* [Angular Data Grid Context Menu](https://www.telerik.com/kendo-angular-ui-develop/components/grid/accessories/context-menu)
