> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cognite.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Visualize events

> Set up and filter queries on CDF events and annotate the events to graphs on your Grafana dashboard.

You can customize the time range, the events to display, and the columns according to your needs.

<a id="work-with-events-in-a-table" />

## Work with events in a table

Open the <span class="ui-element">Event</span> tab in <span translate="no">Grafana</span> to work with the events in a table.

<Frame>
  <img src="https://apps-cdn.cogniteapp.com/@cognite/docs-portal-images/1.0.0/images/cdf/dashboards/grafana/event-table.png" alt="Events in table" width="100%" />
</Frame>

<a id="define-a-query" />

### Define a query

The `events` query uses the [events/list](/api-reference/concepts/20230101/events) endpoint to retrieve data.

**Format:** `events{someFilter=number, otherFilter="string"}`

**Example:**

```text theme={"languages":{"custom":["/_languages/kuiper.json","../_languages/kuiper.json"]}}
events{externalIdPrefix='WORKORDER', assetSubtreeIds=[{id=12}, {externalId='ext_id'}]}
```

You can filter on these properties:
`externalIdPrefix`, `metadata`, `assetIds`, `assetExternalIds`, `rootAssetIds`, `assetSubtreeIds`, `dataSetIds`, `source`, `type`, and `subtype`.

By default, the query returns active events in the time range, but you can customize a query with the additional time filters `startTime`, `endTime`, `activeAtTime`, `createdTime`, and `lastUpdatedTime`.

This example returns all finished events that started in the current time range:

```text theme={"languages":{"custom":["/_languages/kuiper.json","../_languages/kuiper.json"]}}
events{startTime={min=$__from}, endTime={isNull=false}}
```

This example returns only finished events:

```text theme={"languages":{"custom":["/_languages/kuiper.json","../_languages/kuiper.json"]}}
events{endTime={isNull=false}}
```

**Client-side filtering**

Specify more client-side filtering with the `=~`, `!~`, and `!=` operators. A comma between several filters acts as a logical `AND`.

**Format:**

* `=~` - regex equality. Returns results satisfying the regular expression.

* `!~` - regex inequality. Excludes results satisfying the regular expression.

* `!=` - strict inequality. Returns items where a property doesn't equal a given value.

**Example:**

```text theme={"languages":{"custom":["/_languages/kuiper.json","../_languages/kuiper.json"]}}
events{type='WORKORDER', subtype=~'SUB.*'}
```

<Info>
  Don't use the client-side filters as the primary filtering method.
  <span translate="no">Grafana</span> applies the filters after items have been returned from <span translate="no">CDF</span>, and you may not see all data if <span translate="no">CDF</span> returns the maximum number of items (1000).
</Info>

**Create templates**

Create templates by using the `$variable_name` syntax.

**Example:**

```text theme={"languages":{"custom":["/_languages/kuiper.json","../_languages/kuiper.json"]}}
events{type='WORKORDER', subtype=$variable}
```

<a id="rename-and-organize-fields" />

### Rename and organize fields

Select the <span class="ui-element">Transform</span> tab to rename and organize fields.

<Frame>
  <img src="https://apps-cdn.cogniteapp.com/@cognite/docs-portal-images/1.0.0/images/cdf/dashboards/grafana/rename_columns.png" alt="Rename columns" width="100%" />
</Frame>

<a id="annotate-graphs-with-events" />

## Annotate graphs with events

Use annotations to overlay rich event information from <span translate="no">CDF</span> on graphs in <span translate="no">Grafana</span>.

<Steps>
  <Step title="Open dashboard annotations settings">
    Navigate to your dashboard's settings, and select <span class="ui-element">Annotations</span>.
  </Step>

  <Step title="Select the data source">
    Select your <span translate="no">CDF</span> project in the <span class="ui-element">Data Source</span> field.

    <Frame>
      <img src="https://apps-cdn.cogniteapp.com/@cognite/docs-portal-images/1.0.0/images/cdf/dashboards/grafana/add_annotation.png" alt="Annotation query" width="100%" />
    </Frame>
  </Step>

  <Step title="Specify the query">
    Specify the query to fetch and filter events from <span translate="no">CDF</span>. For example:

    ```text theme={"languages":{"custom":["/_languages/kuiper.json","../_languages/kuiper.json"]}}
    events{type="some", subtype=~"sub.*"}
    ```

    The query above requests events with parameter `type="some"` and filters the results by `subtype` that matches `sub.*`.

    * For a complete list of **valid parameters**, see [the API documentation](/api-reference/concepts/20230101/events).

    * Learn how to [**filter**](/cdf/dashboards/guides/grafana/timeseries_legacy#filtering) the results.

    <Frame>
      <img src="https://apps-cdn.cogniteapp.com/@cognite/docs-portal-images/1.0.0/images/cdf/dashboards/grafana/use_annotation.png" alt="Use annotation" width="100%" />
    </Frame>
  </Step>
</Steps>
