i using jfreechart make boxplot (code @ bottom). when don't add a coloring per box drawn wide , correctly centered (as want them):
however, when color them x-axis label, smaller , not centered correctly anymore:
how can coloring of second figure box sizes of first?
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))); (string k : test.keyset()){ /* change * string xaxislabel = ""; * 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); } }
the difference first picture has 1 series, second picture has 5 series. instead of adding lots of series, add 1 series 5 items top picture. can use custom boxandwhiskerrenderer
overrides getitempaint()
different colors show here xylineandshaperenderer
.
edit: matching legend, need new drawingsupplier
this.
Comments
Post a Comment