Crosshair X,Y location on Panel

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
m3stevep
Posts: 13
Joined: Sun Oct 22, 2006 2:42 am
Location: UTAH, USA
Contact:

Crosshair X,Y location on Panel

Post by m3stevep » Tue Nov 07, 2006 9:54 am

Is there a way to get the X and Y values for the XYPlot's crosshair location? Read carefully before you answer.

plot.getDomainCrosshairValue() gives the value for X in the Dataset, but I'd like to know the X value on the panel to position some text relative to the crosshair location.

It'd be nice if there was a method like plot.getDomainCrosshairLocation or something like that.

If there is already something like this, I'd really love to learn about it.

Thanks in advance!!

SteveP

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue Nov 07, 2006 10:44 am

The ScatterPlotDemo3.java source file contains code (in the chartMouseClicked() method) for converting from Java2D coordinates to data values, and from data values to Java2D coordinates.
David Gilbert
JFreeChart Project Leader

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

m3stevep
Posts: 13
Joined: Sun Oct 22, 2006 2:42 am
Location: UTAH, USA
Contact:

Post by m3stevep » Sun Nov 12, 2006 7:45 am

Worked great! Thanks!

btw... This is how I implemented it... where mouseX & mouseY are used in the main panel.

private void evaluateScreenMouseXY(XYPlot plot, XYDataItem di) {

ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo();
Rectangle2D dataArea = info.getPlotInfo().getDataArea();
ValueAxis domainAxis = plot.getDomainAxis();
ValueAxis rangeAxis = plot.getRangeAxis();

double xxx = domainAxis.valueToJava2D(di.getX().doubleValue(), dataArea, plot.getDomainAxisEdge());
double yyy = rangeAxis.valueToJava2D(di.getY().doubleValue(), dataArea, plot.getRangeAxisEdge());

Point2D p2 = this.chartPanel.translateJava2DToScreen(new Point2D.Double(xxx, yyy));
mouseX = new Double(p2.getX()).intValue();
mouseY = new Double(p2.getY()).intValue();
}

Locked