How to retrieve XYItemEntity from Domain/RangeCrosshair

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
snoopygee
Posts: 18
Joined: Wed Jan 28, 2009 3:10 pm

How to retrieve XYItemEntity from Domain/RangeCrosshair

Post by snoopygee » Mon Feb 23, 2009 11:30 am

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

kandidat
Posts: 7
Joined: Thu Dec 04, 2008 11:39 pm

Re: How to retrieve XYItemEntity from Domain/RangeCrosshair

Post by kandidat » Wed Mar 04, 2009 9:04 pm

Hi,

i have the same problem. Did you or anybody find a solution?

In the Documentation is no hint for that.

Oliver

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Re: How to retrieve XYItemEntity from Domain/RangeCrosshair

Post by RichardWest » Thu Mar 05, 2009 12:00 am

You can get the value of the crosshairs via getDomainCrosshairValue() and getRangeCrosshairValue().

kandidat
Posts: 7
Joined: Thu Dec 04, 2008 11:39 pm

Re: How to retrieve XYItemEntity from Domain/RangeCrosshair

Post by kandidat » Thu Mar 05, 2009 11:17 am

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.

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);
I think there must be an easier way to get the ixx-value, like int getDomainCrosshairItemIndex() or XYItem getDomainCrosshairItem()
Oliver

david.gilbert
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

Post by david.gilbert » Thu Mar 05, 2009 10:25 pm

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

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

stefan__
Posts: 4
Joined: Thu Jan 07, 2010 4:17 pm
antibot: No, of course not.

Re: How to retrieve XYItemEntity from Domain/RangeCrosshair

Post by stefan__ » Fri Jan 08, 2010 3:27 pm

David,

do you know the status of this feature request, i.e Is it being worked on or under consideration?

regards,
Stefan

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: How to retrieve XYItemEntity from Domain/RangeCrosshair

Post by paradoxoff » Tue Jan 12, 2010 9:42 pm

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.

morgandev
Posts: 3
Joined: Sat Dec 09, 2006 1:41 am

Re: How to retrieve XYItemEntity from Domain/RangeCrosshair

Post by morgandev » Wed Dec 01, 2010 12:52 am

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.

Locked