2016-07-15 9 views
2

Ich habe eine Frage zu JFreeChart: Ist es möglich, die PlotOrientation eines BoxAndWhiskerChart zu horizontal zu ändern? Ich habe ein Histogramm, und ich möchte ein BoxAndWhiskerChart unten hinzufügen. Ich brauche es horizontal, damit ich die gleiche Achsenskala verwenden kann. Ich habe versucht, die Ausrichtung in Plot und ChartPanel zu ändern.PlotOrientation von BoxAndWhiskerChart JFreeChart

the look of my JFrame

Antwort

1

@Catalina Insel zeigt den richtigen Weg, um die PlotOrientationhere, zu ändern, aber Sie können für PlotOrientation.HORIZONTAL in einen Fehler in den BoxAndWhiskerRenderer weiter unten ausgeführt werden. Beachten Sie die abgeschnittene Linie auf dem unteren Whisker.

Original image

Das Problem ist here in drawHorizontalItem():

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

Updated image

-Code wie geprüft::

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

was das sein sollte

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

Melden Sie sich an [hier] (http://www.jfree.org/forum/viewtopic.php?f=3&t=117622). – trashgod

1

können Sie die PlotOrientation auf dem wie diese CategoryPlot ändern.

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