Click here to Skip to main content
16,004,974 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In MFC MS Chart Control how to see values of chart points when the mouse is on points?

Thanks.

What I have tried:

In the link c# - see values of chart points when the mouse is on points - Stack Overflow[^], c# code is given to achieve my requirement but I dont know what is equivalent code in c++ for the below c# code.
chart1.HitTest(pos.X, pos.Y, false,ChartElementType.DataPoint);
Posted
Updated 19-Jun-18 0:48am

If you check the method on MSDN, you can click on the C++ tab to see the equivalent in that language:

Chart.HitTest Method (Int32, Int32, Boolean, ChartElementType[]) (System.Windows.Forms.DataVisualization.Charting)[^]
 
Share this answer
 
Comments
[no name] 19-Jun-18 4:55am    
In MFC the chart control is not having HitTest function.
In any CWnd based class you can override CWnd::OnMouseMove in your derived class:
// In CMyClass header file:
//afx_msg void OnMouseMove(UINT nFlags,  CPoint point);

// In CMyClass source file
BEGIN_MESSAGE_MAP(CMyClass, CBaseClass)
    ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()

void CMyClass::OnMouseMove(UINT nFlags, CPoint point)
{
    // Note that this called repeatedly so that execution should
    //  not consume too much time.

    // Add your code here.
    // Check if the CPoint (relative to the upper-left corner if the CWnd)
    //  is on the chart.
    // If so, calculate the value using the proerties of the chart and display them.

    CBaseClass::OnMouseMove(nFlags, point);
}

If that does not work with the MS Chart Control (I have never used it), you can capture the mouse in your parent window hosting the chart control (see SetCapture() at the above CWnd link). Note that doing so disables all mouse features of the control.

Anyway, I suggest to use one of the many MFC chart control implementations that can be found in the web instead of this ancient control.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900