How to retrieve XYItemEntity from Domain/RangeCrosshair
How to retrieve XYItemEntity from Domain/RangeCrosshair
Hi,
I have set the following in my chart:
XYPlot.DomainCrosshairVisible(true)
XYPlot.DomainCrosshairVisible(true)
This enables the functionality that wherever I click on the chart the doman and range crosshairs jump to the nearest data point on my chart. This functionality is exactly what I'm looking for.
The problem is that I cannot seem to identify the XYItemEntity that the crosshair lines have repositioned themselves over. The ChartMouseListener only returns information regarding the actual position that you clicked your mouse, but not the new position that the crosshairs have been placed.
Any ideas how to retrieve the new position and therefore the valid XYItemEntity?
Thanks
I have set the following in my chart:
XYPlot.DomainCrosshairVisible(true)
XYPlot.DomainCrosshairVisible(true)
This enables the functionality that wherever I click on the chart the doman and range crosshairs jump to the nearest data point on my chart. This functionality is exactly what I'm looking for.
The problem is that I cannot seem to identify the XYItemEntity that the crosshair lines have repositioned themselves over. The ChartMouseListener only returns information regarding the actual position that you clicked your mouse, but not the new position that the crosshairs have been placed.
Any ideas how to retrieve the new position and therefore the valid XYItemEntity?
Thanks
Re: How to retrieve XYItemEntity from Domain/RangeCrosshair
Hi,
i have the same problem. Did you or anybody find a solution?
In the Documentation is no hint for that.
Oliver
i have the same problem. Did you or anybody find a solution?
In the Documentation is no hint for that.
Oliver
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
Re: How to retrieve XYItemEntity from Domain/RangeCrosshair
You can get the value of the crosshairs via getDomainCrosshairValue() and getRangeCrosshairValue().
Re: How to retrieve XYItemEntity from Domain/RangeCrosshair
RIchard,
to get the Value is not the Problem. I want to get the Dataset or exactly the Item on the Dataset on which th crosshair is actually "connected".
I fond a solution, but i hope i can find it easier.
I think there must be an easier way to get the ixx-value, like int getDomainCrosshairItemIndex() or XYItem getDomainCrosshairItem()
Oliver
to get the Value is not the Problem. I want to get the Dataset or exactly the Item on the Dataset on which th crosshair is actually "connected".
I fond a solution, but i hope i can find it easier.
Code: Select all
// Transferring Domainx-Values to items
// 5000 6000 10000 Domain values 6000 is the selected DomainValue
// 0 x 1000 items in the plot
// I'm searching for x
double vdiff = itemN-item1; // 5000
double vdiff2 = domainCrosshairValue - item1; // =1000
double vquot = vdiff2/vdiff; // =1/5
double ixx = itemCount * vquot; // =200;
// with ixx i can get now the the y-values of other datasets in the plot.
double y = datasetCollection.getYValue(datasetIndex, (int)ixx);
Oliver
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: How to retrieve XYItemEntity from Domain/RangeCrosshair
The CrosshairState object (used temporarily by the XYPlot class to track/update the crosshair position as each renderer processes data values) does record the dataset index but never makes that accessible to the outside world. It probably makes sense to add 'seriesIndex' and 'itemIndex' to the info being collected, then write that into fields on the XYPlot class (as we do currently for the actual values) then you could retrieve the indices after the plot is drawn. Can you enter a Feature Request in the database at SourceForge and reference this thread in it?
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Re: How to retrieve XYItemEntity from Domain/RangeCrosshair
David,
do you know the status of this feature request, i.e Is it being worked on or under consideration?
regards,
Stefan
do you know the status of this feature request, i.e Is it being worked on or under consideration?
regards,
Stefan
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: How to retrieve XYItemEntity from Domain/RangeCrosshair
Since neither the feature request nor the patch list contains a relevant entry, I assume that this feature is not on the todo list.
In principal it should be easy to add the missing methods to the CrosshairState class, but the additional series and item index are meaningless for a CategoryPlots. The CategoryPlot uses an instance of CategoryCrosshairState for tracking which offers to store the row key and column key.
Consequently, one could use an instance of XYCrosshairState for an XYPlot. Interestingly, this class is already included in JFreeChart. It has no methods except a non argument constructor, but the missing methods could be easily added. Unfortunately, the drawItem method of XYItemRenderer only uses an instance of CrosshairState, not XYCrosshairState. Changing that would break the XYItemRenderer interface!
Since the CrosshairState is only used in AbstractXYItemRenderer.updateCrosshairValues(CrosshairState, double, double, int, int, double, double, PlotOrientation) one could still perform the necessary cast from CrosshairState to XYCrosshairState in this method.
Once the series and item index are stored in the XYCrosshairState instance, it should be trivial to add the missing private fields and public getters get[Dataset/Series/Item]IndexAtCrosshair.
In principal it should be easy to add the missing methods to the CrosshairState class, but the additional series and item index are meaningless for a CategoryPlots. The CategoryPlot uses an instance of CategoryCrosshairState for tracking which offers to store the row key and column key.
Consequently, one could use an instance of XYCrosshairState for an XYPlot. Interestingly, this class is already included in JFreeChart. It has no methods except a non argument constructor, but the missing methods could be easily added. Unfortunately, the drawItem method of XYItemRenderer only uses an instance of CrosshairState, not XYCrosshairState. Changing that would break the XYItemRenderer interface!
Since the CrosshairState is only used in AbstractXYItemRenderer.updateCrosshairValues(CrosshairState, double, double, int, int, double, double, PlotOrientation) one could still perform the necessary cast from CrosshairState to XYCrosshairState in this method.
Once the series and item index are stored in the XYCrosshairState instance, it should be trivial to add the missing private fields and public getters get[Dataset/Series/Item]IndexAtCrosshair.
Re: How to retrieve XYItemEntity from Domain/RangeCrosshair
This would be very nice, and would match functionality already available for category plots.
I've added it to the feature request list
https://sourceforge.net/tracker/?func=d ... tid=365494
As far as I can tell, this will require a change to the signature of AbstractXYItemRenderer.updateCrosshairValues and the committers might be wary of making this change. In the meantime I'm going to create a XYItemRenderer proxy to wrap every renderer and track the last change to the CrosshairState.
I've added it to the feature request list

https://sourceforge.net/tracker/?func=d ... tid=365494
As far as I can tell, this will require a change to the signature of AbstractXYItemRenderer.updateCrosshairValues and the committers might be wary of making this change. In the meantime I'm going to create a XYItemRenderer proxy to wrap every renderer and track the last change to the CrosshairState.