How to get Xaxis value on chart click |
Post Reply |
Author | |
mohitagandotra
Newbie Joined: 15 December 2011 Status: Offline Points: 1 |
Post Options
Thanks(0)
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..
|
|
SlateColt
Newbie Joined: 09 December 2011 Status: Offline Points: 5 |
Post Options
Thanks(0)
|
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...
} |
|
seanma
Newbie Joined: 13 February 2012 Status: Offline Points: 3 |
Post Options
Thanks(0)
|
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! |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |