JFreeChart的系列刀尖形状上面标注 [英] JFreechart series tool tip above shape annotation

查看:426
本文介绍了JFreeChart的系列刀尖形状上面标注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这是一个系列,并XYPlot一对夫妇的动态添加注释形状无填充(因此每种一系列点可见)。是否有可能以显示系列工具提示(即显示在其上的鼠标指针当前指向的一系列点的坐标),在注解?或者为了使工具提示可见我怎么能重新安排元素。

I have an XYPlot on which are series and a couple of dynamically added shape annotations with no fill (hence each of the series points are visible). Is it possible to display the series tool tips(that show the coordinate of the series point over which the mouse pointer is currently pointing to) over the annotations? Or how can I re-arrange the elements in order to make the tooltip visible.

推荐答案

我怀疑你所添加的注释形状的情节,在那里他们被吸引过去。相反,它们添加到渲染器 Layer.BACKGROUND 。如下图所示,圈内确实的的掩盖在(20,20)刀尖。还要注意(10,10)是怎样的的受线标注,而(30,30)的的由电弧遮挡。

I suspect you are adding the shape annotations to the plot, where they are drawn last. Instead, add them to the renderer in Layer.BACKGROUND. As shown below, the circle does not obscure the tool tip at (20, 20). Note also how (10, 10) is not affected by the line annotation, while (30, 30) is obscured by the arc.

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.geom.Arc2D;
import java.awt.geom.Ellipse2D;
import java.util.Random;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.annotations.XYLineAnnotation;
import org.jfree.chart.annotations.XYShapeAnnotation;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.Layer;

/**
 * @see http://stackoverflow.com/questions/6797012
 * @see http://stackoverflow.com/questions/6604211
 */
public class ArcTest {

    private static final Random r = new Random();
    private static final Color blue = Color.blue;
    private static final BasicStroke stroke = new BasicStroke(2.0f);
    private static final double PI = 180d;
    private static final int X = 8;
    private static final int Y = 0;
    private static final int W = 6 * X;
    private static final int H = 3 * X;

    public static void main(String[] args) {
        JFreeChart chart = ChartFactory.createXYLineChart(
            "ArcTest", "X", "Y", createDataset(),
            PlotOrientation.VERTICAL, true, true, false);
        XYPlot plot = chart.getXYPlot();

        XYLineAndShapeRenderer renderer =
            (XYLineAndShapeRenderer) plot.getRenderer();
        renderer.setBaseShapesVisible(true);
        Ellipse2D.Double circle = new Ellipse2D.Double(X, X, 20, 20);
        renderer.addAnnotation(new XYShapeAnnotation(
            circle, stroke, blue), Layer.BACKGROUND);

        XYLineAnnotation line = new XYLineAnnotation(X, Y, X, H, stroke, blue);
        plot.addAnnotation(line);
        Arc2D.Double arc = new Arc2D.Double(X, Y, W, 2 * H, PI, PI, Arc2D.OPEN);
        plot.addAnnotation(new XYShapeAnnotation(arc, stroke, blue));

        ChartFrame frame = new ChartFrame("Test", chart);
        frame.pack();
        frame.setVisible(true);
    }

    private static XYDataset createDataset() {
        XYSeriesCollection result = new XYSeriesCollection();
        XYSeries series = new XYSeries("ArcTest");
        series.add(0, 0);
        series.add(10, 10);
        series.add(20, 20);
        series.add(30, 30);
        series.add(W, W);
        result.addSeries(series);
        return result;
    }
}

这篇关于JFreeChart的系列刀尖形状上面标注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆