Back to Devexpress

How to: Show Series Labels Only for Hot-tracked Points

windowsforms-8689-controls-and-libraries-chart-control-examples-end-user-interaction-how-to-show-series-labels-only-for-hot-tracked-points.md

latest3.4 KB
Original Source

How to: Show Series Labels Only for Hot-tracked Points

  • Nov 13, 2018
  • 2 minutes to read

This example demonstrates how to make a chart show a series point label only for the point that has been hot-tracked.

To do this, in the ChartControl.CustomDrawSeriesPoint event handler, assign an empty string to the CustomDrawSeriesPointEventArgs.LabelText property of each series point, and then assign the point’s value to the hot-tracked point, which is obtained in the ChartControl.ObjectHotTracked event handler.

csharp
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
        SeriesPoint m_HotTrackedPoint;

        void chartControl1_ObjectHotTracked(object sender, HotTrackEventArgs e)
        {
            SeriesPoint point = e.AdditionalObject as SeriesPoint;
            if (!Object.ReferenceEquals(point, m_HotTrackedPoint))
            {
                m_HotTrackedPoint = point;
                chartControl1.Refresh();
            }
        }

        void chartControl1_CustomDrawSeriesPoint(object sender, CustomDrawSeriesPointEventArgs e)
        {

            if (!Object.Equals(e.SeriesPoint, m_HotTrackedPoint))
            {
                e.LabelText = "";
            }
        }
vb
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
        Private m_HotTrackedPoint As SeriesPoint

        Private Sub chartControl1_ObjectHotTracked(ByVal sender As Object, ByVal e As HotTrackEventArgs) Handles chartControl1.ObjectHotTracked
            Dim point As SeriesPoint = TryCast(e.AdditionalObject, SeriesPoint)
            If Not Object.ReferenceEquals(point, m_HotTrackedPoint) Then
                m_HotTrackedPoint = point
                chartControl1.Refresh()
            End If
        End Sub

        Private Sub chartControl1_CustomDrawSeriesPoint(ByVal sender As Object, ByVal e As CustomDrawSeriesPointEventArgs) Handles chartControl1.CustomDrawSeriesPoint

            If Not Object.Equals(e.SeriesPoint, m_HotTrackedPoint) Then
                e.LabelText = ""
            End If
        End Sub

The result is shown in the following image.

See Also

How to: Determine a Chart Element the Mouse Pointer Hovers Over

How to: Determine which Series Point Is Under the Test Point

How to: Show Information from a Datasource Field in a Crosshair Cursor Label

How to: Create a Text Annotation Anchored to a Series Point