2016-07-15 3 views
2

질문이 있습니까 JFreeChart : PlotOrientationBoxAndWhiskerChart으로 바꾸는 것이 가능합니까? 히스토그램이 있는데 아래에 BoxAndWhiskerChart을 추가하고 싶습니다. 나는 같은 축척을 사용할 수 있도록 수평이 필요하다. PlotChartPanel의 방향을 변경하려고했습니다.BoxAndWhiskerChart의 PlotOrientation JFreeChart

the look of my JFrame

답변

1

@Catalina 섬은 PlotOrientationhere을 변경할 수있는 올바른 방법을 보여줍니다,하지만 당신은 PlotOrientation.HORIZONTAL을 위해 아래의 BoxAndWhiskerRenderer의 버그로 실행할 수 있습니다. 더 낮은 수염 자에 잘린 선을주의하십시오.

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

이 있어야하는 :

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

Updated image

코드 테스트로 :

Original image

문제는 heredrawHorizontalItem()

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);