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
Crosshair X,Y location on Panel
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


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();
}
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();
}