질문이 있습니까 JFreeChart
: PlotOrientation
을 BoxAndWhiskerChart
으로 바꾸는 것이 가능합니까? 히스토그램이 있는데 아래에 BoxAndWhiskerChart
을 추가하고 싶습니다. 나는 같은 축척을 사용할 수 있도록 수평이 필요하다. Plot
및 ChartPanel
의 방향을 변경하려고했습니다.BoxAndWhiskerChart의 PlotOrientation JFreeChart
2
A
답변
1
@Catalina 섬은 PlotOrientation
here을 변경할 수있는 올바른 방법을 보여줍니다,하지만 당신은 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));
코드 테스트로 :
문제는 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);
}
}
1
이 같은 CategoryPlot
에 PlotOrientation
을 변경할 수 있습니다.
CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setOrientation(PlotOrientation.HORIZONTAL);
제출 된 보고서 및 수정 [여기] (http://www.jfree.org/forum/viewtopic.php?f=3&t=117622). – trashgod