Author |
Topic  |
|
Mark
2 Posts |
Posted - 08 Apr 2005 : 13:54:55
|
I would like to detect mouse over for the individual bar on a bar char and point on a line plot. Is this possible? I can of'course detect mouse over the graph, but how can I determine which bar for example the mouse is over. |
|
quinncurtis
1164 Posts |
Posted - 08 Apr 2005 : 15:13:54
|
There are many ways to do this, using our MouseListener, DataToolTip, FindObj, DataCursor classes. A simple, direct way to do this is to just override the OnMouseDown event of the ChartView class you are using to display the plots, and use the plot objects CheckIntersection method to test for a hit and to get the selected data point index, as seen below. The thePlot1 object is an instantiated SimpleLinePlot, or SimpleBarPlot object. You could also override the ChartView.OnMouseUp or ChartView.OnMouseMove events in the same manner.
public class SimpleBarChart : com.quinncurtis.chart2dnet.ChartView { SimpleBarPlot thePlot1;
public SimpleBarChart() { // This call is required by the Windows Form Designer. InitializeComponent();
// TODO: Add any initialization after the InitializeComponent call InitializeChart(); }
private void InitializeChart() { ChartView chartVu = this; . . .
}
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) { Point2D testpoint = new Point2D(e.X, e.Y); NearestPointData np = new NearestPointData(); int selectedbarindex = -1; if ( thePlot1.CheckIntersection( testpoint, np)) { selectedbarindex = np.NearestPointIndex; }
base.OnMouseDown(e); }
} |
 |
|
|
Topic  |
|
|
|