2016-07-15 3 views
2

私はJFreeChartについて質問があります:BoxAndWhiskerChartPlotOrientationを水平に変更できますか?ヒストグラムがあり、下にを追加したいと思います。私はそれが同じ軸スケールを使用することができるように水平にする必要があります。 PlotChartPanelの方向を変更しようとしました。BoxAndWhiskerChartのPlotOrientation JFreeChart

the look of my JFrame

答えて

1

@Catalina島はPlotOrientationhereを変更する正しい方法を示していますが、PlotOrientation.HORIZONTALのために、以下に示すBoxAndWhiskerRendererのバグに遭遇することがあります。下のウィスカーの切り捨てられた線に注意してください。

Original image

問題がdrawHorizontalItem()here次のとおりです。

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

このあるべき:

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

Updated image

テストとしてコード:

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); 
    } 
} 
+0

[こちら](http://www.jfree.org/forum/viewtopic.php?f=3&t=117622)のレポートと修正が提出されました。 – trashgod

1

あなたはこのようなCategoryPlotPlotOrientationを変更することができます。

CategoryPlot plot = (CategoryPlot) chart.getPlot(); 
plot.setOrientation(PlotOrientation.HORIZONTAL);