1
JFreeChartを使ってボックスプロット(下側のコード)を作っています。私は(私はそれらをしたいと)彼らは広い描かれ、正しくセンタリングされているボックスあたりAA着色を追加しない場合:JFreechartボックスの色を変えるときのボックスのサイズを変更する
を私はその後、x軸ラベルによってそれらを色付けする場合しかし、彼らは小さく取得し、もはや正しくセンタリングされていません。
は、どのように私は2番目の図のが、最初のボックスのサイズとカラーリングを得ることができますか?
package test;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.BoxAndWhiskerToolTipGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.renderer.category.BoxAndWhiskerRenderer;
import org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset;
public class test {
public static void main(String[] args) throws Exception {
DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
// example data
HashMap<String, ArrayList<Double>> test = new HashMap<String, ArrayList<Double>>();
test.put("A",new ArrayList<Double>(Arrays.asList(0.8, 1.4, 0.8, 1.9, 1.2)));
test.put("B",new ArrayList<Double>(Arrays.asList(0.8, 1.4, 0.8, 1.9, 1.2)));
test.put("C",new ArrayList<Double>(Arrays.asList(0.8, 1.4, 0.8, 1.9, 1.2)));
test.put("D",new ArrayList<Double>(Arrays.asList(0.8, 1.4, 0.8, 1.9, 1.2)));
test.put("E",new ArrayList<Double>(Arrays.asList(0.8, 1.4, 0.8, 1.9, 1.2)));
for (String k : test.keySet()){
/* change to
* String xAxisLabel = "";
* to get wide plot
*/
String xAxisLabel = k;
dataset.add(test.get(k), xAxisLabel, k);// + beta of interactionterm");
}
final CategoryAxis xAxis = new CategoryAxis("Example x-axis");
final NumberAxis yAxis = new NumberAxis("Example y-axis");
yAxis.setAutoRangeIncludesZero(false);
final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
renderer.setFillBox(true);
renderer.setSeriesToolTipGenerator(1, new BoxAndWhiskerToolTipGenerator());
renderer.setMeanVisible(false);
final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
final JFreeChart chart = new JFreeChart(
"Example",
plot
);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(3000,1800));
ChartUtilities.saveChartAsPNG(new File("test.png"), chart, 1000, 600);
}
}
これは良い例です。 http://www.java2s.com/Code/Java/Chart/JFreeChartBarChartDemo3differentcolorswithinaseries.htm – SamTew
ああ、それは私を思い出させる。一致する凡例を取得するには、新しい['DrawingSupplier'](https://stackoverflow.com/a/13010394/261156)が必要です。 –