Print Page | Close Window

How to get Xaxis value on chart click

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Chart Control
Forum Description: Topics Related to Codejock Chart Control
URL: http://forum.codejock.com/forum_posts.asp?TID=19310
Printed Date: 29 April 2024 at 3:21am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: How to get Xaxis value on chart click
Posted By: mohitagandotra
Subject: How to get Xaxis value on chart click
Date 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..



Replies:
Posted By: SlateColt
Date 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...

}



Posted By: seanma
Date 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!



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net