java - XY 图 : Annotation is placed incorrectly with respect to Y axis

标签 java jfreechart

我有以下代码,可在鼠标单击事件的 XYPlot 中生成注释。

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

除了 Y 轴之外,一切正常(参见下面的示例)。当我单击系列点(红色箭头)时,注释出现在另一个位置(该位置相对于 X 轴是正确的,但相对于 Y 轴是不正确的)。

enter image description here

最佳答案

当您调用 java2dToValue() 计算 y 值时,您正在指定 RectangleEdge.BOTTOM 作为轴位置,但它应该是 RectangleEdge。左

关于java - XY 图 : Annotation is placed incorrectly with respect to Y axis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35266151/

相关文章:

JAVA:-将HashMap中存储的对象转换为sql日期类型

javascript - 为什么我不能用 javascript 清除输入字段?

从 Eclipse 运行时不显示 Java JFrame 窗口

java - 在 jfreechart/PiePlot3D 饼图上隐藏标签

java - 在 hibernate 条件查询中选择 "all columns"和 "group by"

java - Maven 将 "Release Note"部署为 Artifact

java - 方法 setFont() 不适用于参数 [JLabel] (eclipse)

java - 如何根据数据集中的值设置 JasperStudio 中 barChart 中条形的颜色?

java - 堆积面积图,固定 y 轴标签宽度

android - Afree图表: How to increase X axis values(gap or domain range) while zooming