# GraphWidget

A dashboard widget that displays metrics.

Extends: ConcreteWidget › GraphWidget
Implements: IWidget

- Source: [`aws-cloudwatch/lib/graph.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts#L449)

## Example

```ts
declare const dashboard: cloudwatch.Dashboard;

dashboard.addWidgets(new cloudwatch.GraphWidget({
  // ...
  accountId: '123456789012',
}));

dashboard.addWidgets(new cloudwatch.LogQueryWidget({
  logGroupNames: ['my-log-group'],
  // ...
  accountId: '123456789012',
  queryLines: [
    'fields @message',
  ],
}));
```

## Initializer

```ts
new GraphWidget(props: GraphWidgetProps)
```

## Properties

- `height`: number (required) — The amount of vertical grid units the widget will take up.

- `warnings`: string[] — Any warnings that are produced as a result of putting together this widget.

- `warningsV2`: { [key: string]: string } — Any warnings that are produced as a result of putting together this widget.

- `width`: number (required) — The amount of horizontal grid units the widget will take up.

## Methods

- `addLeftMetric(metric: IMetric): void` — Add another metric to the left Y axis of the GraphWidget.

  **Parameters**

  - `metric` — the metric to add.

- `addRightMetric(metric: IMetric): void` — Add another metric to the right Y axis of the GraphWidget.

  **Parameters**

  - `metric` — the metric to add.

- `position(x: number, y: number): void` — Place the widget at a given position.

- `toJson(): any[]` — Return the widget JSON for use in the dashboard.
