BoxAndWhiskerRenderer with PlotOrientation.HORIZONTAL

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

BoxAndWhiskerRenderer with PlotOrientation.HORIZONTAL

Post by John Matthews » Sat Jul 16, 2016 5:25 am

I haven't seen a report of this problem with BoxAndWhiskerRenderer when used with a plot having PlotOrientation.HORIZONTAL; note the truncated lower whisker.

Image

The following change to drawHorizontalItem() seems to correct the rendering.

Code: Select all

$ diff -c OldBoxAndWhiskerRenderer.java source/org/jfree/chart/renderer/category/BoxAndWhiskerRenderer.java
*** OldBoxAndWhiskerRenderer.java	2016-07-15 23:42:35.000000000 -0400
--- source/org/jfree/chart/renderer/category/BoxAndWhiskerRenderer.java	2016-07-15 23:42:41.000000000 -0400
***************
*** 704,710 ****
              // draw the lower shadow...
              g2.draw(new Line2D.Double(xxMin, yymid, xxQ1, yymid));
              g2.draw(new Line2D.Double(xxMin, yymid - halfW, xxMin,
!                     yy + halfW));
  
              g2.setStroke(getItemOutlineStroke(row, column));
              g2.setPaint(outlinePaint);
--- 704,710 ----
              // draw the lower shadow...
              g2.draw(new Line2D.Double(xxMin, yymid, xxQ1, yymid));
              g2.draw(new Line2D.Double(xxMin, yymid - halfW, xxMin,
!                     yymid + halfW));
  
              g2.setStroke(getItemOutlineStroke(row, column));
              g2.setPaint(outlinePaint);
Image

SSCCE:

Code: Select all

import java.awt.Dimension;
import java.awt.EventQueue;
import java.util.Arrays;
import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset;

/**
 * @see http://stackoverflow.com/a/38407595/230513
 */
public class BoxPlot {


    private void display() {
        JFrame f = new JFrame("BoxPlot");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        DefaultBoxAndWhiskerCategoryDataset data = new DefaultBoxAndWhiskerCategoryDataset();
        data.add(Arrays.asList(30, 36, 46, 55, 65, 76, 81, 80, 71, 59, 44, 34), "Planet", "Endor");
        JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(
            "Box and Whisker Chart", "Planet", "Temperature", data, false);
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.setOrientation(PlotOrientation.HORIZONTAL);
        f.add(new ChartPanel(chart) {

            @Override
            public Dimension getPreferredSize() {
                return new Dimension(500, 300);
            }
        });
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new BoxPlot()::display);
    }
}

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: BoxAndWhiskerRenderer with PlotOrientation.HORIZONTAL

Post by david.gilbert » Mon Jul 18, 2016 7:56 pm

Thanks John, I committed that fix just now.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked