CrosshairLabelElement Class
Namespace: DevExpress.Xpf.Charts
Assembly:
DevExpress.Xpf.Charts.v20.2.dll
NuGet Packages:
DevExpress.WindowsDesktop.Wpf.Charts, DevExpress.Wpf.Charts
Declaration
[NonCategorized]
public class CrosshairLabelElement :
CrosshairTemplatedLabelElement
<NonCategorized>
Public Class CrosshairLabelElement
Inherits CrosshairTemplatedLabelElement
The following members return CrosshairLabelElement objects:
To get access to the appearance properties of the CrosshairLabelElement object, use the DevExpress.Xpf.Charts.CrosshairElement.LabelElement property.
For more information on crosshair cursors, see Tooltip and Crosshair Cursor.
Example
This example shows how to provide a custom appearance for the crosshair cursor using the ChartControl.CustomDrawCrosshair event. This event is invoked when you click the Custom Draw Crosshair Cursor button on the form.
If you wish to display crosshair axis lines and labels on a chart before custom drawing the crosshair cursor, set the CrosshairOptions.ShowArgumentLabels, CrosshairOptions.ShowArgumentLine, CrosshairOptions.ShowValueLabels and CrosshairOptionsBase.ShowValueLine properties to true.
Note that the customization of the crosshair cursor is provided for the CrosshairOptions.SnapMode property set to NearestArgument.
View Example
<Window x:Class="CrosshairCustomDraw.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts">
<Grid>
<StackPanel>
<dxc:ChartControl Height="269" Name="chartControl1" CustomDrawCrosshair="chartControl1_CustomDrawCrosshair">
<dxc:ChartControl.CrosshairOptions>
<dxc:CrosshairOptions ShowArgumentLabels="True" ShowArgumentLine="True"
ShowValueLabels="True" ShowValueLine="True"/>
</dxc:ChartControl.CrosshairOptions>
<dxc:XYDiagram2D>
<dxc:LineSeries2D DisplayName="Series1">
<dxc:SeriesPoint Argument="1" Value="50"/>
<dxc:SeriesPoint Argument="2" Value="44"/>
<dxc:SeriesPoint Argument="3" Value="55"/>
<dxc:SeriesPoint Argument="4" Value="77"/>
</dxc:LineSeries2D>
<dxc:LineSeries2D DisplayName="Series2">
<dxc:SeriesPoint Argument="1" Value="22"/>
<dxc:SeriesPoint Argument="2" Value="11"/>
<dxc:SeriesPoint Argument="3" Value="9"/>
<dxc:SeriesPoint Argument="4" Value="8"/>
</dxc:LineSeries2D>
</dxc:XYDiagram2D>
</dxc:ChartControl>
<Button Height="35" Content="Custom Draw Crosshair Cursor" Click="Button_Click"></Button>
</StackPanel>
</Grid>
</Window>
using System.Windows;
using DevExpress.Xpf.Charts;
using System.Windows.Media;
namespace CrosshairCustomDraw {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
bool handleCustomDraw;
public MainWindow() {
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e) {
handleCustomDraw = true;
chartControl1.CustomDrawCrosshair += chartControl1_CustomDrawCrosshair;
}
private void chartControl1_CustomDrawCrosshair(object sender, CustomDrawCrosshairEventArgs e) {
if (!handleCustomDraw) return;
// Specify the crosshair argument line color, dash style and thickness.
e.CrosshairLineElement.Brush = Brushes.Aqua;
e.CrosshairLineElement.LineStyle.DashStyle = DashStyles.DashDot;
e.CrosshairLineElement.LineStyle.Thickness = 3;
// Specify the back color for crosshair argument label.
foreach (CrosshairAxisLabelElement axisLabelElement in e.CrosshairAxisLabelElements)
axisLabelElement.Background = Brushes.Blue;
foreach (CrosshairElementGroup group in e.CrosshairElementGroups) {
CrosshairElement element = group.CrosshairElements[0];
// Specify the color, dash style and thickness for the crosshair value lines.
element.LineElement.Brush = Brushes.DarkViolet;
element.LineElement.LineStyle.DashStyle = DashStyles.Dash;
element.LineElement.LineStyle.Thickness = 2;
// Specify the font size and background for the crosshair value labels.
element.AxisLabelElement.FontSize = 14;
element.AxisLabelElement.Background = Brushes.Red;
// Specify the foreground and font size for the crosshair cursor label that shows series.
element.LabelElement.Foreground = Brushes.Green;
element.LabelElement.FontSize = 14;
}
foreach (CrosshairElementGroup group in e.CrosshairElementGroups) {
CrosshairGroupHeaderElement groupHeaderElement = group.HeaderElement;
// Specify the text, text color and font for the crosshair group header element.
groupHeaderElement.Text = "Custom draw";
groupHeaderElement.Foreground = Brushes.Red;
groupHeaderElement.FontSize = 15;
}
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Windows
Namespace CrosshairCustomDraw
''' <summary>
''' Interaction logic for App.xaml
''' </summary>
Partial Public Class App
Inherits Application
End Class
End Namespace
<Application x:Class="CrosshairCustomDraw.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
Imports System.Windows
Imports DevExpress.Xpf.Charts
Imports System.Windows.Media
Namespace CrosshairCustomDraw
''' <summary>
''' Interaction logic for MainWindow.xaml
''' </summary>
Partial Public Class MainWindow
Inherits Window
Private handleCustomDraw As Boolean
Public Sub New()
InitializeComponent()
End Sub
Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
handleCustomDraw = True
AddHandler chartControl1.CustomDrawCrosshair, AddressOf chartControl1_CustomDrawCrosshair
End Sub
Private Sub chartControl1_CustomDrawCrosshair(ByVal sender As Object, ByVal e As CustomDrawCrosshairEventArgs)
If Not handleCustomDraw Then
Return
End If
' Specify the crosshair argument line color, dash style and thickness.
e.CrosshairLineElement.Brush = Brushes.Aqua
e.CrosshairLineElement.LineStyle.DashStyle = DashStyles.DashDot
e.CrosshairLineElement.LineStyle.Thickness = 3
' Specify the back color for crosshair argument label.
For Each axisLabelElement As CrosshairAxisLabelElement In e.CrosshairAxisLabelElements
axisLabelElement.Background = Brushes.Blue
Next axisLabelElement
For Each group As CrosshairElementGroup In e.CrosshairElementGroups
Dim element As CrosshairElement = group.CrosshairElements(0)
' Specify the color, dash style and thickness for the crosshair value lines.
element.LineElement.Brush = Brushes.DarkViolet
element.LineElement.LineStyle.DashStyle = DashStyles.Dash
element.LineElement.LineStyle.Thickness = 2
' Specify the font size and background for the crosshair value labels.
element.AxisLabelElement.FontSize = 14
element.AxisLabelElement.Background = Brushes.Red
' Specify the foreground and font size for the crosshair cursor label that shows series.
element.LabelElement.Foreground = Brushes.Green
element.LabelElement.FontSize = 14
Next group
For Each group As CrosshairElementGroup In e.CrosshairElementGroups
Dim groupHeaderElement As CrosshairGroupHeaderElement = group.HeaderElement
' Specify the text, text color and font for the crosshair group header element.
groupHeaderElement.Text = "Custom draw"
groupHeaderElement.Foreground = Brushes.Red
groupHeaderElement.FontSize = 15
Next group
End Sub
End Class
End Namespace
See Also