jfreechart - JFreeChart:十字准线标签自定义位置
问题描述
是否可以将十字准线标签放置在自定义位置?我有 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);
}
推荐阅读
- perl - 管理 HTTP 错误的模块
- node.js - 聚合函数返回 null GraphQL
- git - 如何从 GitHub 下载包
- asp.net-mvc - [Authorize] 属性如何知道用户在 ASP.NET MVC 中进行了身份验证,是使用身份验证令牌吗?
- javascript - 使用 MobX 存储循环引用设置测试
- c# - 由于缺少合适的构造函数,aspnet core 2.1 动作过滤器出错
- php - 如何将一个数组合并到另一个数组的子级(递归)?
- javascript - 服务器终止时保存文件
- linux - 在 Linux 中频繁轮换日志时如何复制所需的日志文件内容
- c++ - Qt Creator 调试器日志窗口不必要地转义了许多字符使输出分散注意力