JFreeChart:十字标签自定义位置

问题描述 投票:0回答:1

是否可以将十字准线标签放在自定义位置?我有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);

我在鼠标监听器中有标签所需的绘图坐标,但我找不到如何将其应用到标签位置。

jfreechart
1个回答
0
投票

好的,我已经通过使用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);
}
© www.soinside.com 2019 - 2024. All rights reserved.