BoxAndWhiskerChart JFreeChart的图方向 [英] PlotOrientation of BoxAndWhiskerChart JFreeChart

查看:100
本文介绍了BoxAndWhiskerChart JFreeChart的图方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对JFreeChart有疑问:是否可以将BoxAndWhiskerChartPlotOrientation更改为水平?我有一个直方图,我想在下面添加一个BoxAndWhiskerChart.我需要水平放置,以便可以使用相同的轴刻度.我试图更改PlotChartPanel的方向.

I have a question about JFreeChart: Is it possible to change the PlotOrientation of a BoxAndWhiskerChart to horizontal? I have a histogram, and I want to add a BoxAndWhiskerChart below. I need it horizontal so I can use the same axis scale. I tried to change the orientation in the Plot and ChartPanel.

推荐答案

@卡塔利娜岛(Catalina Island)显示了更改PlotOrientation PlotOrientation.HORIZONTAL的rel ="nofollow noreferrer"> BoxAndWhiskerRenderer 如下所示.请注意下晶须上的截断线.

@Catalina Island shows the correct way to change the PlotOrientation here, but you may run into a bug in the BoxAndWhiskerRenderer shown below for PlotOrientation.HORIZONTAL. Note the truncated line on the lower whisker.

问题是drawHorizontalItem()此处 >

The problem is here in drawHorizontalItem():

g2.draw(new Line2D.Double(xxMin, yymid - halfW, xxMin, yy + halfW));

应该是这样的:

g2.draw(new Line2D.Double(xxMin, yymid - halfW, xxMin, yymid + halfW));

经过测试的代码

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 https://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);
    }
}

这篇关于BoxAndWhiskerChart JFreeChart的图方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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