I am trying to come up with the code to take the location of a mouse pointer and determine the value of the domain and value axis that cooresponds to that location.
I set up a ChartMouseListener on the ChartPanel and can pick up the X and Y coordinates from the MouseEvent trigger in the chartMouseMoved method. But I can't figure out how to get from X,Y to the axis values. I also expect that the pointer can be between points. Which means I have to also pick the closest value to any specific point. I have searched and searched the API and can't find anything that obviously does either function for me. I sure could use a suggestion.
What I am trying to accomplish is to pick up the proper axis data values and display them at the crosshair lines.
Determining axis values at a mouse poisition
Re: Determining axis values at a mouse poisition
This is what I do to get the domain/range coordinates:
Hope this will help you
Code: Select all
double x = plot.getDomainAxis().java2DToValue(cp.translateScreenToJava2D(evt.getTrigger().getPoint()).getX(),cp.getChartRenderingInfo().getPlotInfo().getDataArea(),plot.getDomainAxisEdge());
double y = plot.getRangeAxis().java2DToValue(cp.translateScreenToJava2D(evt.getTrigger().getPoint()).getY(),cp.getChartRenderingInfo().getPlotInfo().getDataArea(),plot.getRangeAxisEdge());
Re: Determining axis values at a mouse poisition
That helped a lot. I am now able to get the value of the x and y axis. Thank you very much!!!
One more question. Is it possible to also get the index of the domain axis instead of the actual value?
One more question. Is it possible to also get the index of the domain axis instead of the actual value?
Re: Determining axis values at a mouse poisition
I'm not sure if this is what you want ::
Code: Select all
int rowIndex = dataset.getRowIndex(((CategoryItemEntity)evt.getEntity()).getRowKey());
int columnIndex = dataset.getColumnIndex(((CategoryItemEntity)evt.getEntity()).getColumnKey());