JFreeChart:十字线标签自定义位置
JFreeChart: crosshair label custom position
是否可以在自定义位置放置十字准线标签?我有 x 和 y 十字线。我希望 y 十字准线标签位于数据点附近(更改标签偏移 X 坐标)。
问题是 RectangleAnchor 没有这样的选项
Crosshair yCrosshair = new Crosshair(Double.NaN, Color.DARK_GRAY, new BasicStroke(0f));
yCrosshair.setLabelAnchor(RectangleAnchor.CENTER);
而且 JFreeChart 似乎完全忽略了标签偏移设置:
Crosshair yCrosshair = new Crosshair(Double.NaN, Color.DARK_GRAY, new BasicStroke(0f));
yCrosshair.setLabelXOffset(5);
我在鼠标侦听器中有所需的标签绘图坐标,但我找不到如何将其应用到标签位置。
好的,我已经使用 XYPointerAnnotation 解决了我的问题。
XYPointerAnnotation pointer = new XYPointerAnnotation( "", 0, 0, 7.0 * Math.PI / 4.0 );
pointer.setTipRadius(3.0);
pointer.setBaseRadius(15.0);
pointer.setPaint(Color.blue);
pointer.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
pointer.setBackgroundPaint(new Color(180, 180, 180, 180));
在鼠标移动事件中,我将注释定位到所需的点
mainPlot.removeAnnotation(pointer);
if ( !sY.isNaN() ) {
pointer.setX(x);
pointer.setY(sY);
pointer.setText("POWER: "+ sY);
mainPlot.addAnnotation(pointer);
}
是否可以在自定义位置放置十字准线标签?我有 x 和 y 十字线。我希望 y 十字准线标签位于数据点附近(更改标签偏移 X 坐标)。
问题是 RectangleAnchor 没有这样的选项
Crosshair yCrosshair = new Crosshair(Double.NaN, Color.DARK_GRAY, new BasicStroke(0f));
yCrosshair.setLabelAnchor(RectangleAnchor.CENTER);
而且 JFreeChart 似乎完全忽略了标签偏移设置:
Crosshair yCrosshair = new Crosshair(Double.NaN, Color.DARK_GRAY, new BasicStroke(0f));
yCrosshair.setLabelXOffset(5);
我在鼠标侦听器中有所需的标签绘图坐标,但我找不到如何将其应用到标签位置。
好的,我已经使用 XYPointerAnnotation 解决了我的问题。
XYPointerAnnotation pointer = new XYPointerAnnotation( "", 0, 0, 7.0 * Math.PI / 4.0 );
pointer.setTipRadius(3.0);
pointer.setBaseRadius(15.0);
pointer.setPaint(Color.blue);
pointer.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
pointer.setBackgroundPaint(new Color(180, 180, 180, 180));
在鼠标移动事件中,我将注释定位到所需的点
mainPlot.removeAnnotation(pointer);
if ( !sY.isNaN() ) {
pointer.setX(x);
pointer.setY(sY);
pointer.setText("POWER: "+ sY);
mainPlot.addAnnotation(pointer);
}