use of org.jfree.chart.renderer.category.BoxAndWhiskerRenderer in project gephi by gephi.
the class ChartsUtils method buildBoxPlot.
/**
* Build a new box-plot from an array of numbers using a default title and yLabel.
* String dataName will be used for xLabel.
* @param numbers Numbers for building box-plot
* @param dataName Name of the numbers data
* @return Prepared box-plot
*/
public static JFreeChart buildBoxPlot(final Number[] numbers, final String dataName) {
if (numbers == null || numbers.length == 0) {
return null;
}
DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
final ArrayList<Number> list = new ArrayList<>();
list.addAll(Arrays.asList(numbers));
final String valuesString = getMessage("ChartsUtils.report.box-plot.values");
dataset.add(list, valuesString, "");
final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
renderer.setMeanVisible(false);
renderer.setFillBox(false);
renderer.setMaximumBarWidth(0.5);
final CategoryAxis xAxis = new CategoryAxis(dataName);
final NumberAxis yAxis = new NumberAxis(getMessage("ChartsUtils.report.box-plot.values-range"));
yAxis.setAutoRangeIncludesZero(false);
renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
plot.setRenderer(renderer);
JFreeChart boxPlot = new JFreeChart(getMessage("ChartsUtils.report.box-plot.title"), plot);
return boxPlot;
}
Aggregations