Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Chart Control
  New Posts New Posts RSS Feed - Reading x-axis y-axis values according to mousemov
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Reading x-axis y-axis values according to mousemov

 Post Reply Post Reply
Author
Message
suji View Drop Down
Groupie
Groupie


Joined: 04 April 2018
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote suji Quote  Post ReplyReply Direct Link To This Post Topic: Reading x-axis y-axis values according to mousemov
    Posted: 30 January 2019 at 1:35am
I want to read the values of the x and y axes according to mousemove.


class CChartContents : public CXTPChartControl
{
     DECLARE_DYNAMIC(CChartContents)

public:
     CChartContents();
     virtual ~CChartContents();

protected:
     DECLARE_MESSAGE_MAP()
public:
     afx_msg void OnMouseMove(UINT nFlags, CPoint point);
};


void CChartContents::OnMouseMove(UINT nFlags, CPoint point)
{
     TRACE(_T("\nx:%d, y:%d\n"), point.x, point.y);
     CXTPChartElement* pTemp = HitTest(point);
     CXTPChartControl::OnMouseMove(nFlags, point);
}


I have read the mouse point position value of chartcontrol.
But what I need, the x, y value of the graph for the mouse point.
Is there a way to read it?

If the mouse position is at the red dot, you should read the value of x = 33, y = 20.



Back to Top
BobC View Drop Down
Groupie
Groupie


Joined: 28 April 2017
Location: Longmont, CO
Status: Offline
Points: 55
Post Options Post Options   Thanks (0) Thanks(0)   Quote BobC Quote  Post ReplyReply Direct Link To This Post Posted: 02 February 2019 at 7:44pm
Here is a code snippet for what I use when a user clicks on a point in the chart. It should be enough to get you going for code to use in your mouse move handler. 

My chart has dates across the X axis and a dollar value up the Y axis. When the user clicks a point on the chart, this code displays the date and dollar value.

"pt" is the CPoint that was clicked, m_oChart is a CXTPChartControl object.


CXTPChartContent* pContent = m_oChart.GetContent();
ASSERT(pContent);
CXTPChartSeriesCollection* pCollection = pContent->GetSeries();
ASSERT(pCollection);
CXTPChartDiagram2D* pDiagram = DYNAMIC_DOWNCAST(CXTPChartDiagram2D, pCollection->GetAt(0)->GetDiagram());
ASSERT(pDiagram);

// Get the chart's internal X coordinate...
double internalValueX = ((CXTPChartDiagram2DAxisView*)pDiagram->GetAxisX()->GetAxisView())->PointToValue(pt.x);

// ...and convert it to a date string
CXTPChartString valueX = pDiagram->GetAxisX()->GetScaleTypeMap()->InternalToValue(pDiagram->GetAxisX()->GetLabel()->GetFormat(), internalValueX);
std::string sDate = boost::nowide::narrow(valueX.GetBuffer());

// Get the chart's Y coordinate...
double valueY = ((CXTPChartDiagram2DAxisView*)pDiagram->GetAxisY()->GetAxisView())->PointToValue(pt.y);

// ...and convert it to a dollar value
isomon::money oMoney((int64_t)valueY, (int64_t)(valueY / 100.0), "USD");
std::string sMoney = jrnlmoney::MoneyToString(oMoney, true);

// display the info
std::stringstream ss;
ss << "Date: " << sDate << "\r\nValue: " << sMoney;
::MessageBoxW(m_hWnd, boost::nowide::widen(ss.str()).c_str(), L"Point Values", MB_OK | MB_ICONINFORMATION);

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.