Back to Devexpress

CustomDrawCrosshairEventArgs.CrosshairLegendElements Property

corelibraries-devexpress-dot-xtracharts-dot-customdrawcrosshaireventargs-d75013b8.md

latest6.0 KB
Original Source

CustomDrawCrosshairEventArgs.CrosshairLegendElements Property

Returns crosshair legend elements to customize their appearance.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
public IList<CrosshairLegendElement> CrosshairLegendElements { get; }
vb
Public ReadOnly Property CrosshairLegendElements As IList(Of CrosshairLegendElement)

Property Value

TypeDescription
IList<CrosshairLegendElement>

A collection of CrosshairLegendElement objects.

|

Remarks

If the CrosshairOptions.ContentShowMode (or SeriesBase.CrosshairContentShowMode) property is Legend , use the CrosshairLegendElements property to customize legend elements when custom drawing a crosshair cursor using the ChartControl.CustomDrawCrosshair event.

Refer to the Tooltip and Crosshair Cursor document for more information on the Crosshair Cursor.

Example

This example demonstrates how to modify the Crosshair Cursor’s appearance using the ChartControl.CustomDrawCrosshair event.

In this sample, crosshair content is displayed in a legend. For this, set the CrosshairOptions.ContentShowMode to the Legend value that the CrosshairContentShowMode enumeration contains. Note that you can specify the crosshair’s content show mode for the specified series using the SeriesBase.CrosshairContentShowMode property.

Use the CustomDrawCrosshairEventArgs.CrosshairLegendElements property to obtain the crosshair legend elements’ collection.

To customize crosshair legend element options, use the CrosshairLegendElement class properties:

csharp
private void Form1_Load(object sender, System.EventArgs e) {
    chartControl.CrosshairOptions.ContentShowMode = CrosshairContentShowMode.Legend;
    chartControl.CrosshairOptions.ShowValueLabels = true;
    chartControl.CrosshairOptions.ShowValueLine = true;
}
private void OnCustomDrawCrosshair(object sender, CustomDrawCrosshairEventArgs e) {
    foreach(CrosshairLegendElement legendElement in e.CrosshairLegendElements) {
        legendElement.TextColor = (legendElement.SeriesPoint.Values[0] > ColorSelectorValue) ? Color.Green : Color.Red;
        legendElement.LineElement.Color = legendElement.TextColor;
        legendElement.AxisLabelElement.BackColor = legendElement.TextColor;
    }
}
vb
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    chartControl.CrosshairOptions.ContentShowMode = CrosshairContentShowMode.Legend
    chartControl.CrosshairOptions.ShowValueLabels = True
    chartControl.CrosshairOptions.ShowValueLine = True
End Sub
Private Sub OnCustomDrawCrosshair(ByVal sender As Object, ByVal e As CustomDrawCrosshairEventArgs) Handles chartControl.CustomDrawCrosshair
    For Each legendElement As CrosshairLegendElement In e.CrosshairLegendElements
        legendElement.TextColor = If(legendElement.SeriesPoint.Values(0) > ColorSelectorValue, Color.Green, Color.Red)
        legendElement.LineElement.Color = legendElement.TextColor
        legendElement.AxisLabelElement.BackColor = legendElement.TextColor
    Next legendElement
End Sub

See Also

CustomDrawCrosshairEventArgs Class

CustomDrawCrosshairEventArgs Members

DevExpress.XtraCharts Namespace