How can I draw round corners in the frame where the serie's legends are?

I want it to look like the following image: enter image description here

Thank you for your help

有帮助吗?

解决方案 2

After some research, I finally solve it.

It's easy, just ask the char for its legend and then its Frame. Finally overwrite BlockFrame Interface with the basic Shape you want to use in your legend.

     jfreechart.getLegend().setFrame(new  BlockFrame() {

        /** The space reserved for the border. */
        private RectangleInsets insets = new RectangleInsets(1, 1, 1, 1);

        /** The border color. */
        private transient Paint paint = new Color(117,170,219);

        @Override
        public RectangleInsets getInsets() {
            return insets;
        }

        @Override
        public void draw(Graphics2D g2, Rectangle2D area) {
            Dimension arcs = new Dimension(45,45);
            double t = this.insets.calculateTopInset(area.getHeight());
            double b = this.insets.calculateBottomInset(area.getHeight());
            double l = this.insets.calculateLeftInset(area.getWidth());
            double r = this.insets.calculateRightInset(area.getWidth());
            double x = area.getX();
            double y = area.getY();
            double w = area.getWidth();
            double h = area.getHeight();
            g2.setPaint(this.paint);
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);


            RoundRectangle2D myrect= new RoundRectangle2D.Double();

            if (t > 0.0) {
                myrect.setRoundRect(x, y, w, t,arcs.width, arcs.height);
                g2.fill(myrect);
            }
            if (b > 0.0) {
                myrect.setRoundRect(x, y + h - b, w, b,arcs.width, arcs.height);
                g2.fill(myrect);
            }
            if (l > 0.0) {
                myrect.setRoundRect(x, y, l, h,arcs.width, arcs.height);
                g2.fill(myrect);
            }
            if (r > 0.0) {
                myrect.setRoundRect(x + w - r, y, r, h,arcs.width, arcs.height);
                g2.fill(myrect);
            }
        }
    });

其他提示

You can apply a round cornered border, seen here, to a custom legend panel, seen here.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top