Skip to main content

DevExpress v25.1 Update — Your Feedback Matters

Our What's New in v25.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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

  • 2 minutes to read

The following example handles the ChartControl.MouseMove event to identify the chart element under the mouse pointer and display its name in the form’s caption.

Note

Turn on the ChartControl.RuntimeHitTesting option to enable hit testing.

using DevExpress.XtraCharts;
using System.Windows.Forms;

namespace DXApplication {
    public partial class Form1 : DevExpress.XtraEditors.XtraForm {
        public Form1() {
            InitializeComponent();
            chartControl1.MouseMove += ChartControl1_MouseMove;
            chartControl1.RuntimeHitTesting = true;
        }

        void ChartControl1_MouseMove(object sender, MouseEventArgs e) {
            ChartHitInfo hi = chartControl1.CalcHitInfo(new System.Drawing.Point(e.X, e.Y));
            this.Text = hi.HitTest.ToString();
        }
    }
}

#Identify the Series Name on Mouse Move

The following example obtains the name of the series under the mouse pointer and displays it in the form’s caption:

C#
using DevExpress.XtraCharts;
using System.Windows.Forms;

namespace DXApplication {
    public partial class Form1 : DevExpress.XtraEditors.XtraForm {
        public Form1() {
            InitializeComponent();
            chartControl1.MouseMove += ChartControl1_MouseMove;
            chartControl1.RuntimeHitTesting = true;
        }

        void ChartControl1_MouseMove(object sender, MouseEventArgs e) {
            ChartHitInfo hi = chartControl1.CalcHitInfo(new System.Drawing.Point(e.X, e.Y));
            if(hi.HitTest == ChartHitTest.Series){
                this.Text = ((Series)hi.Series).Name;
            }
        }
    }
}
See Also