---
title: Crosshair
order: 985
seealso: []
---

# Crosshair


The Cartesian Chart control includes a crosshair that allows you to see exact series values at the current cursor position. Rendered as a pair of horizontal and vertical lines, the crosshair follows the mouse pointer as it hovers over the diagram area. It displays a series label (or multiple labels for multiple series) that shows the series value, and highlights the current _X_ and _Y_ coordinates on the axes.


![chart-crosshair-one-series](/docs/images/chart-crosshair-one-series.png)

To customize display settings of the crosshair, or disable this feature, initialize the `CartesianChart.CrosshairOptions` property with an instance of the `Eremex.AvaloniaUI.Charts.CrosshairOptions` class. Then use the properties exposed by the `CrosshairOptions` class to adjust the crosshair settings as needed.


## Disable the Crosshair

The `CrosshairOptions.ShowCrosshair` property allows you to disable the crosshair.

``` xml
<mxc:CartesianChart x:Name="chartControl1" >
    <mxc:CartesianChart.CrosshairOptions>
        <mxc:CrosshairOptions ShowCrosshair="False"/>
    </mxc:CartesianChart.CrosshairOptions>
    <!-- ... -->
</mxc:CartesianChart>
```

## Disable Individual Lines and Axis Labels of the Crosshair

The `CrosshairOptions.ShowArgumentLine` and `CrosshairOptions.ShowValueLine` properties can be used to hide the vertical and horizontal line of the crosshair, respectively. To prevent crosshair labels from being displayed for the _X_ and _Y_ axes, use the `CrosshairOptions.ShowArgumentLabel` and `CrosshairOptions.ShowValueLabel` properties.

The following example hides the crosshair's vertical line and label for the _X_ axis:

![chart-crosshair-vertical-line-hidden](/docs/images/chart-crosshair-vertical-line-hidden.png)

``` xml
<mxc:CartesianChart x:Name="chartControl1" >
    <mxc:CartesianChart.CrosshairOptions>
        <mxc:CrosshairOptions ShowArgumentLabel="False" ShowValueLabel="False"/>
    </mxc:CartesianChart.CrosshairOptions>
    <!-- ... -->
</mxc:CartesianChart>
```

## Customize Crosshair Series Labels

The crosshair series labels display the names and current values of the series.

![chart-crosshair-chart-labels](/docs/images/chart-crosshair-chart-labels.png)

### Format Values in Crosshair Series Labels

The values displayed in the crosshair labels use default formats initially:

![chart-crosshair-chart-labels-no-formatting](/docs/images/chart-crosshair-chart-labels-no-formatting.png)

To format these values in a custom manner, create a formatter object and assign it to the `Axis.ScaleOptions.CrosshairLabelFormatter` property. Axis values can be [formatted](cartesian-chart.md#format-axis-labels) similarly (see the `Axis.ScaleOptions.LabelFormatter` property). 

You can implement a custom label formatter based on a function/expression using the `Eremex.AvaloniaUI.Charts.FuncLabelFormatter` object.

The following example creates a formatter object that formats numeric values as currency. This formatter is used to format _Y_ axis values and values in the crosshair series label.

![chart-crosshair-chart-labels-formatting-example](/docs/images/chart-crosshair-chart-labels-formatting-example.png)

``` xml
<mxc:CartesianChart.AxesY>
    <mxc:AxisY Title="Payment">
        <mxc:AxisY.ScaleOptions>
            <mxc:NumericScaleOptions
                CrosshairLabelFormatter="{Binding CurrencyFormatter}"
                LabelFormatter="{Binding CurrencyFormatter}"/>
        </mxc:AxisY.ScaleOptions>
    </mxc:AxisY>
</mxc:CartesianChart.AxesY>
```

``` cs
public partial class MainViewModel : ViewModelBase 
{
[ObservableProperty] 
FuncLabelFormatter currencyFormatter = new(o => String.Format("{0:c}", o));
}
```


<!-- 
TODO
### Change the Template of Crosshair Series Labels 

-->


### Hide a Series in the Crosshair

A series view's `CrosshairSeriesViewBase.ShowInCrosshair` property specifies the visibility of this series in the crosshair label.

<!-- TODO
Add an image of the crosshair chart label, as many other topics refer to this section
 -->

The following code defines two series (_Interest_ and _Principal_). The `ShowInCrosshair` property is set to `false` for the first series to hide it in the crosshair:


``` xml
<mxc:CartesianChart.Series>
    <mxc:CartesianSeries DataAdapter="{Binding InterestSeriesDataAdapter}" SeriesName="Interest">
        <mxc:CartesianAreaSeriesView Color="#F9A825" Transparency="0.2" 
          MarkerSize="2" ShowMarkers="True"
          ShowInCrosshair="False" />
    </mxc:CartesianSeries>

    <mxc:CartesianSeries DataAdapter="{Binding PrincipalSeriesDataAdapter}" SeriesName="Principal">
        <mxc:CartesianAreaSeriesView Color="#2E7D32" Transparency="0.2" MarkerSize="2" ShowMarkers="True" />
    </mxc:CartesianSeries>
</mxc:CartesianChart.Series>
```

![chart-crosshair-showincrosshair-disabled](/docs/images/chart-crosshair-showincrosshair-disabled.png)

### Horizontal Indent of the Crosshair Series Label

The `CrosshairOptions.SeriesLabelIndent` property allows you to adjust the horizontal distance between the crosshair series label and the crosshair vertical line. The property's default value is 2.

![chart-crosshair-serieslabelindent](/docs/images/chart-crosshair-serieslabelindent.png)

``` xml
<mxc:CartesianChart.CrosshairOptions>
    <mxc:CrosshairOptions SeriesLabelIndent="30"/>
</mxc:CartesianChart.CrosshairOptions>
```


### Show an Exact or Interpolated Value in Crosshair Series Labels

Cartesian Chart supports series that consist of sorted discrete data points. For these series, the crosshair lines do not always intersect data points, but are most often displayed between them. 
You can use the `CartesianSortedLineSeriesView.CrosshairMode` property to specify whether the crosshair label snaps to the nearest data point, or displays an interpolated value. The following options are available:

- `CrosshairSeriesMode.Point` — The crosshair label snaps to the nearest data point and displays its value.
  
  ![chart-CrosshairSeriesMode-Point](/docs/images/chart-CrosshairSeriesMode-Point.png)

- `CrosshairSeriesMode.Interpolate` — The crosshair series label displays an interpolated value of the point at the intersection of the vertical crosshair line with the chart.

  ![chart-CrosshairSeriesMode-Interpolate](/docs/images/chart-CrosshairSeriesMode-Interpolate.png)

The following code shows how to customize the `CrosshairMode` option:

``` xml
<mxc:CartesianChart.Series>
    <mxc:CartesianSeries DataAdapter="{Binding Series.DataAdapter}">
        <mxc:CartesianLineSeriesView Color="{Binding Series.Color}" Thickness="2" CrosshairMode="Interpolate"/>
    </mxc:CartesianSeries>
</mxc:CartesianChart.Series>

```

### Customize Crosshair Labels for Multiple Series

#### Label Display Mode

When the Cartesian Chart contains multiple series, the crosshair displays a label for each series:

![chart-crosshair-two-series ](/docs/images/chart-crosshair-two-series.png)

The `CrosshairOptions.SeriesLabelMode` property specifies whether and how multiple series labels are combined. The following options are available:

- `CrosshairSeriesLabelMode.Smart` (default) — Each series displays its own crosshair label. When labels overlap, they are combined in a single label.
  
  ![chart-CrosshairSeriesLabelMode-smart](/docs/images/chart-CrosshairSeriesLabelMode-smart.png)


- `CrosshairSeriesLabelMode.ForEachSeries` — Each series displays its own crosshair label. Labels may overlap in this mode.
  
  ![chart-CrosshairSeriesLabelMode-ForEachSeries](/docs/images/chart-CrosshairSeriesLabelMode-ForEachSeries.png)

- `CrosshairSeriesLabelMode.ForNearestSeries` — A crosshair label is displayed only for the series nearest the cursor.
  
  ![chart-CrosshairSeriesLabelMode-ForNearestSeries](/docs/images/chart-CrosshairSeriesLabelMode-ForNearestSeries.png)

- `CrosshairSeriesLabelMode.OneForAllSeries` — The crosshair displays a single label that combines information from all series.

  ![chart-CrosshairSeriesLabelMode-OneForAllSeries](/docs/images/chart-CrosshairSeriesLabelMode-OneForAllSeries.png)

The following example enables a single crosshair label when multiple series are present.

``` xml
<mxc:CartesianChart.CrosshairOptions>
    <mxc:CrosshairOptions SeriesLabelMode="OneForAllSeries"/>
</mxc:CartesianChart.CrosshairOptions>
```

#### Series Sorting

When multiple series are combined in a single crosshair label, you can use the `CrosshairOptions.SeriesLabelItemSortMode` property to specify the display order of the series in the label. This property can be set to the following values:

- `CrosshairSeriesLabelItemSortMode.BySeries` (default) — Sorts series by the order in which these series are added to the `CartesianChart.Series` collection.

    ![chart-CrosshairSeriesLabelItemSortMode-BySeries](/docs/images/chart-CrosshairSeriesLabelItemSortMode-BySeries.png)

- `CrosshairSeriesLabelItemSortMode.ByValue` — Sorts series by their _Y_ values.

    ![chart-CrosshairSeriesLabelItemSortMode-ByValue](/docs/images/chart-CrosshairSeriesLabelItemSortMode-ByValue.png)

## Show Delay

Use the `CrosshairOptions.SeriesLabelShowDelay` property to specify the delay (in milliseconds) before a crosshair series label is displayed.

## Include Only Series Near the Cursor

By default, linear charts display crosshair labels for all series that have data points at the current argument value.

![chart-Crosshair-MaxPickDistance-Disabled](/docs/images/chart-Crosshair-MaxPickDistance-Disabled.png)

The chart control allows you to limit crosshair labels to series near the cursor. Use the `CrosshairOptions.MaxPickDistance` property to specify the range within which to search for data points to include in crosshair labels. For regular linear charts, the `MaxPickDistance` property specifies the maximum vertical distance (in pixels) upward or downward.

![chart-Crosshair-MaxPickDistance](/docs/images/chart-Crosshair-MaxPickDistance.png)

In the image above, only data points from the _Series 1_ and _Series 3_ lie within the range limited by a custom `MaxPickDistance` value. The data point from the _Series 2_ (red line) is beyond this range and is not shown.



For [Scatter Line views](cartesian-series-views/scatter-line-series-view.md), the `MaxPickDistance` property specifies the radius of a circular area around the cursor within which to search for data points.

!!! Tip

    To display a crosshair label for a single series nearest the cursor, set the `CrosshairOptions.SeriesLabelMode` property to `ForNearestSeries`. See [Label Display Mode](#label-display-mode).



## Customize Crosshair Lines and Labels on the _X_ and _Y_ Axes

A chart control's `CrosshairOptions` object contains a set of properties that allow you to change the visual settings of crosshair lines, _X_ axis label, and _Y_ axis label.

- `ArgumentColor` — The background color of the crosshair _X_ axis labels.
- `ArgumentLineThickness` — The thickness of the crosshair argument line.
- `ArgumentTextColor` — The foreground (text) color of the crosshair _X_ axis labels.
- `ValueColor` — The background color of the crosshair _Y_ axis labels.
- `ValueLineThickness` — The thickness of the crosshair value line.
- `ValueTextColor` — The foreground (text) color of the crosshair _Y_ axis labels.

The following XAML code demonstrates how to customize these settings for a sample chart control. The crosshair line thickness is set to 3. The crosshair labels have a gray background, but different text colors: yellow for the _X_-axis labels and cyan for the _Y_-axis labels.

![crosshair-lines-and-labels-customization-example](/docs/images/crosshair-lines-and-labels-customization-example.png)


``` xml
<mxc:CartesianChart ...>
    <mxc:CartesianChart.CrosshairOptions>
        <mxc:CrosshairOptions 
            ArgumentColor="Gray" ArgumentTextColor="Yellow" ArgumentLineThickness="3"
            ValueColor="Gray" ValueTextColor="Cyan" ValueLineThickness="3" />
    </mxc:CartesianChart.CrosshairOptions>
</mxc:CartesianChart>
```