java - XYPlot: Annotation is placed incorrectly with respect to Y axis -
i have following code generates annotation in xyplot on on-mouse-click event.
_chartpanel.addchartmouselistener(new chartmouselistener() { @override public void chartmouseclicked(chartmouseevent cme) { rectangle2d dataarea = _chartpanel.getscreendataarea(); xyplot plot = (xyplot) cme.getchart().getplot(); plot.clearannotations(); valueaxis xaxis = plot.getdomainaxis(); valueaxis yaxis = plot.getrangeaxis(); double x = xaxis.java2dtovalue(cme.gettrigger().getx(), dataarea, rectangleedge.bottom); double y = yaxis.java2dtovalue(cme.gettrigger().gety(), dataarea, rectangleedge.bottom); if (!xaxis.getrange().contains(x)) { x = double.nan; } decimalformat df = new decimalformat("#.##"); df.setroundingmode(roundingmode.ceiling); xypointerannotation pt = new xypointerannotation("lat: " + df.format(y) + "\n lon: " + df.format(x), x, y, 0.2); //pt.setbackgroundpaint(color.red); pt.setarrowpaint(color.red); pt.setfont(_font); pt.setpaint(color.red); plot.addannotation(pt); }
everything works fine except y axis (see example below). when click on series point (red arrow), annotation appears in place (the location correct respect x-axis, while it's incorrect respect y).
when call java2dtovalue()
calculate y-value, specifying rectangleedge.bottom
axis location, should rectangleedge.left
.
Comments
Post a Comment