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 Chart
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