Crosshair Cursor Customization

  • 5 minutes to read

This topic describes different ways to customize crosshair cursor elements and format crosshair label content. It also contains examples of how to do this in applications.

Interaction Customization

Formatting Crosshair Cursor Content

Use a pattern of crosshair axis and crosshair cursor labels

You can change the default format of text displayed within the crosshair labels by specifying a pattern (e.g., only show point values). To accomplish this, use the CrosshairAxisLabelOptions.Pattern, SeriesBase.CrosshairLabelPattern and CrosshairOptions.GroupHeaderPattern properties.

A full list of available placeholders is detailed below.

Pattern Description
{A} Displays a series point argument.
{V} Displays series point values.
{VP} Displays series point values as percentages (for a Pie series and Full-Stacked series).
{S} Displays the name of the series.
{G} Displays the name of a stacked group.
{W} Displays the weight (for a Bubble series).
{V1} Displays the first value (for range series).
{V2} Displays the second value (for range series).
{VD} Displays the duration between the first and second data point values (for range series).
{HV} Displays the high value (for a Financial series).
{LV} Displays the low value (for a Financial series).
{OV} Displays the open value (for a Financial series).
{CV} Displays the close value (for a Financial series).

The Format Specifiers topic explains which standard and custom formats can be used with placeholders to format numeric and date-time values within a crosshair cursor label.

The image below shows the SeriesBase.CrosshairLabelPattern property set to “{S}: {A} - {V}”.

When the chart control or a series is bound to data, the text pattern may contain data field values in addition to default placeholders. For example, if the data source contains the Discount field, then the text pattern may appear as follows: {S}: {V:F2} (Discount: {Discount:P0}). CrosshairLabelPattern

Examples

For real-world examples of how this can be done, see the following tutorial:

Appearance Customization

The following image highlights settings that configure the Crosshair Cursor appearance.

CrosshairOptions

The properties in the table below allow you to customize the common appearance options of the crosshair cursor.

Member Description
CrosshairOptions.ValueLineColor Gets or sets the color of crosshair value lines.
CrosshairOptions.ValueLineStyle Gets the value line style settings of the crosshair cursor.
CrosshairOptions.ArgumentLineColor Gets or sets the color of crosshair argument lines.
CrosshairOptions.ArgumentLineStyle Gets the argument line style settings of the crosshair cursor.
CrosshairOptions.CrosshairLabelBackColor Gets or sets the background color of the Crosshair series label.
CrosshairOptions.CrosshairLabelTextOptions Returns text options of the Crosshair series label item.
CrosshairOptions.GroupHeaderTextOptions Returns text options of the Crosshair series label group header.

Examples

This example illustrates how to display the “Total” point value in the crosshair cursor panel.

To accomplish this task, handle the client-side ASPxClientWebChartControl.CustomDrawCrosshair event and use the last crosshair panel element’s LabelElement.footerText property to display the Total value.

View Example

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register assembly="DevExpress.XtraCharts.v13.2.Web, Version=13.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.XtraCharts.Web" tagprefix="dxchartsui" %>
<%@ Register assembly="DevExpress.XtraCharts.v13.2, Version=13.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.XtraCharts" tagprefix="cc1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <dxchartsui:WebChartControl ID="WebChartControl1" runat="server" ClientInstanceName="chartControl" CrosshairEnabled="True" Height="368px" Width="607px">
            <diagramserializable>
                <cc1:XYDiagram>
                    <axisx visibleinpanesserializable="-1">
                    </axisx>
                    <axisy visibleinpanesserializable="-1">
                    </axisy>
                </cc1:XYDiagram>
            </diagramserializable>
            <seriesserializable>
                <cc1:Series Name="Series 1">
                    <points>
                        <cc1:SeriesPoint ArgumentSerializable="A" Values="100">
                        </cc1:SeriesPoint>
                        <cc1:SeriesPoint ArgumentSerializable="B" Values="50">
                        </cc1:SeriesPoint>
                    </points>
                    <viewserializable>
                        <cc1:StackedBarSeriesView>
                        </cc1:StackedBarSeriesView>
                    </viewserializable>
                </cc1:Series>
                <cc1:Series Name="Series 2">
                    <points>
                        <cc1:SeriesPoint ArgumentSerializable="A" Values="150">
                        </cc1:SeriesPoint>
                        <cc1:SeriesPoint ArgumentSerializable="B" Values="200">
                        </cc1:SeriesPoint>
                    </points>
                    <viewserializable>
                        <cc1:StackedBarSeriesView>
                        </cc1:StackedBarSeriesView>
                    </viewserializable>
                </cc1:Series>
            </seriesserializable>
            <clientsideevents customdrawcrosshair="function(s, e) {
       var summary = 0;
    for (var i = 0; i &lt; e.crosshairElements.length; i++) {        
         summary += e.crosshairElements[i].Point.point.values[0];
     }   
            e.crosshairElements[e.crosshairElements.length - 1].LabelElement.footerText = 'Total :' + summary;
}" />
        </dxchartsui:WebChartControl>

    </div>
    </form>
</body>
</html>
See Also