Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Chart Control
  New Posts New Posts RSS Feed - How to get Xaxis value on chart click
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to get Xaxis value on chart click

 Post Reply Post Reply
Author
Message
mohitagandotra View Drop Down
Newbie
Newbie


Joined: 15 December 2011
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote mohitagandotra Quote  Post ReplyReply Direct Link To This Post Topic: How to get Xaxis value on chart click
    Posted: 15 December 2011 at 7:45am
I want to get corresponding Xaxis value whenever CXTPChart is clicked. On chart click i can get the mouse cursor position and in CAxisView there is a function "double ValueToPoint(double)", to which i can pass the current mouse cursor position and "ValueToPoint" function will return corresponding XAxis value. My query is how to access ValueToPoint function as I dont have view class object. Do I need to create my own view for this..
Back to Top
SlateColt View Drop Down
Newbie
Newbie


Joined: 09 December 2011
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote SlateColt Quote  Post ReplyReply Direct Link To This Post Posted: 05 January 2012 at 11:05am

You want to look at MultipleView.cpp in the chart browser sample app in the OnChartClick method, then add something like this below it:

 
if( DYNAMIC_DOWNCAST( CXTPChartSeriesPoint, pElement ) )
{
   CXTPChartSeriesPoint* pPoint = (CXTPChartSeriesPoint*)pElement;
   TRACE( "clicked series point: %03d value: %4.2f\n", (int)pPoint->GetArgumentValue(),
   pPoint->GetValue(0) );
}
 
Hope this helps...

}

Back to Top
seanma View Drop Down
Newbie
Newbie


Joined: 13 February 2012
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote seanma Quote  Post ReplyReply Direct Link To This Post Posted: 14 February 2012 at 2:11pm
Found a solution.

You will need to define your own derived class of CXTPChartControl, for example myCXTPChartCtrl
and in your derived class, for example, you defined OnLButtonDblClk function,

void myCXTPChartCtrl::OnLButtonDblClk( UINT nFlags, CPoint point )
{
   // here you get which point your mouse click at
   CXTPChartElement* hit =  HitTest ( point );

   // if the hitted element is valid type
   if( hit )
   {
       // if you want to check which data point your clicked on the chart series
       CXTPChartSeriesPoint* pPoint = DYNAMIC_DOWNCAST( CXTPChartSeriesPoint, hit );
      
       // if your hit is actually a point on the series
       if ( pPoint )
       {
            // do whatever you want, for example, get the actual value
           double value = pPoint->GetArgumentValue();
        }
    }
}

The same way, you can get other type of element in the chart (for example, xAxis, yAxis, labels, chart series, markers, legends etc), remember everything is derived class of CXTPChartElement, so you only need to cast them to the type you want.

Happy coding!
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.172 seconds.