How to access elements in a chart in chart control

Asked 2 years ago, Updated 2 years ago, 123 views

VisualBasic.net framework 4.0 Windows 7 uses chart controls to display candle feet.

At this time, I would like to detect which candle feet were clicked by clicking the mouse on the chart for each candle foot, chart.series.item().

Could you please let me know if there is any information that can give me a hint?

Thank you for your cooperation.

vb.net

2022-09-30 21:23

1 Answers

The Chart control provides the HitTest method, which allows you to specify coordinates on the control to examine the objects drawn at that location.Take advantage of this in the Click event

'Find cursor position
Dimpos=DirectCast(e, MouseEventArgs).Location

// DETERMINATION OF ELEMENTS IN CURSOR POSITION
Dim result=Chart1.HitTest(pos.X, pos.Y, ChartElementType.DataPoint)

// determine if there are applicable data points
If result.ChartElementType=ChartElementType.DataPoint Then
    Dimdp=result.Series (result.PointIndex)
    // appropriate treatment

You can distinguish DataPoint by performing a hit test with and looking at the results ChartElementType, Series, PointIndex.If MouseEventArgs is not available, Chart1.PointToClient(MousePosition) will prompt for cursor position.


2022-09-30 21:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.