/** * Creates and returns a default instance of a box and whisker chart * based on data from a {@link BoxAndWhiskerCategoryDataset}. * * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel a label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel a label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * * @return A box and whisker chart. * * @since 1.0.4 */ public static JFreeChart createBoxAndWhiskerChart(String title, String categoryAxisLabel, String valueAxisLabel, BoxAndWhiskerCategoryDataset dataset, boolean legend) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); }
/** * Creates and returns a default instance of a box and whisker chart * based on data from a {@link BoxAndWhiskerCategoryDataset}. * * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel a label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel a label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * * @return A box and whisker chart. * * @since 1.0.4 */ public static JFreeChart createBoxAndWhiskerChart(String title, String categoryAxisLabel, String valueAxisLabel, BoxAndWhiskerCategoryDataset dataset, boolean legend) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Creates and returns a default instance of a box and whisker chart * based on data from a {@link BoxAndWhiskerCategoryDataset}. * * @param title the chart title ({@code null} permitted). * @param categoryAxisLabel a label for the category axis * ({@code null} permitted). * @param valueAxisLabel a label for the value axis ({@code null} * permitted). * @param dataset the dataset for the chart ({@code null} permitted). * @param legend a flag specifying whether or not a legend is required. * * @return A box and whisker chart. * * @since 1.0.4 */ public static JFreeChart createBoxAndWhiskerChart(String title, String categoryAxisLabel, String valueAxisLabel, BoxAndWhiskerCategoryDataset dataset, boolean legend) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setDefaultToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Plots Data for Chart */ private void boxWhiskerPlot() { BoxAndWhiskerCategoryDataset dataset = createDataset(); CategoryAxis xAxis = new CategoryAxis("Model"); NumberAxis yAxis = new NumberAxis("Fitness"); yAxis.setRange(0.0, 1.0); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setMaximumBarWidth(0.2); renderer.setItemMargin(0.5); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.HORIZONTAL); chart = new JFreeChart( "Model comparison", new Font("Palatino", Font.BOLD, 14), plot, true ); chart.removeLegend(); // boxWhiskerPane.setCenter(viewer); }
protected void init() { dataset = new DefaultBoxAndWhiskerCategoryDataset(); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryAxis xAxis = new CategoryAxis("Type"); final NumberAxis yAxis = new NumberAxis("Value"); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); final JFreeChart chart = new JFreeChart( getName(), new Font("SansSerif", Font.BOLD, 14), plot, true ); init(chart.getPlot()); }
public CategoryPlot updateCategoryPlot(CategoryPlot categoryPlot, NumberFormat numberFormat, BoxAndWhiskerItem boxAndWhiskerItem, Color color, boolean notify) { // Box and Whisker Plot NumberAxis valueAxis = new NumberAxis(); valueAxis.setAutoRangeIncludesZero(false); valueAxis.setNumberFormatOverride(numberFormat); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BoxAndWhiskerRenderer boxAndWhiskerRenderer = new BoxAndWhiskerRenderer(); boxAndWhiskerRenderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); boxAndWhiskerRenderer.setMaximumBarWidth(0.3); boxAndWhiskerRenderer.setBasePaint(color); boxAndWhiskerRenderer.setBaseOutlinePaint(color); boxAndWhiskerRenderer.setAutoPopulateSeriesPaint(false); boxAndWhiskerRenderer.setFillBox(false); boxAndWhiskerRenderer.setUseOutlinePaintForWhiskers(true); DefaultBoxAndWhiskerCategoryDataset dbawcd = new DefaultBoxAndWhiskerCategoryDataset(); dbawcd.add(boxAndWhiskerItem, "", ""); categoryPlot.setRenderer(boxAndWhiskerRenderer, notify); categoryPlot.setRangeAxis(0, valueAxis, notify); categoryPlot.setDataset(dbawcd); return categoryPlot; }
/** * Creates a Renderer object to that can draw the BoxPlot. * * @return a BoxAndWhiskerRenderer that can render the boxplot */ private static BoxAndWhiskerRenderer createRenderer( final boolean meanVisible, final boolean fillBox) { BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setMeanVisible(meanVisible); renderer.setFillBox(fillBox); renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); return renderer; }
/** * Simple check that hashCode is implemented. */ public void testHashCode() { BoxAndWhiskerToolTipGenerator g1 = new BoxAndWhiskerToolTipGenerator(); BoxAndWhiskerToolTipGenerator g2 = new BoxAndWhiskerToolTipGenerator(); assertTrue(g1.equals(g2)); assertTrue(g1.hashCode() == g2.hashCode()); }
public JFreeChart getChart() { if (chart == null) { createDataset(); chart = ChartFactory.createBarChart(getTitle(), // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryAxis rangeAxis = plot.getDomainAxis(); rangeAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(true); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); renderer.setMeanVisible(isMeanVisible); plot.setRenderer(renderer); } return chart; }
public void writeToFile(String outName) throws FileNotFoundException, UnsupportedEncodingException, IOException { //calcMeans(); // Create JFreeChart Dataset DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset( ); HashMap<String, ArrayList<Double> > measuresFirst = algorithmMeasures.entrySet().iterator().next().getValue(); for (Map.Entry<String, ArrayList<Double> > measure : measuresFirst.entrySet()) { String measureName = measure.getKey(); //Double measureValue = measure.getValue(); dataset.clear(); for (Map.Entry<String, HashMap<String, ArrayList<Double> >> entry : algorithmMeasures.entrySet()) { String alg = entry.getKey(); ArrayList<Double> measureValues = entry.getValue().get(measureName); // Parse algorithm name to show it correctly String aName = alg.substring(0, alg.length()-1); int startAlgName = aName.lastIndexOf("/"); aName = aName.substring(startAlgName + 1); dataset.add(measureValues, aName, measureName); } // Tutorial: http://www.java2s.com/Code/Java/Chart/JFreeChartBoxAndWhiskerDemo.htm final CategoryAxis xAxis = new CategoryAxis("Algorithm"); final NumberAxis yAxis = new NumberAxis("Value"); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); // Black and White int numItems = algorithmMeasures.size(); for(int i=0;i<numItems;i++) { Color color = Color.DARK_GRAY; if(i%2 == 1) { color = Color.LIGHT_GRAY; } renderer.setSeriesPaint(i, color); renderer.setSeriesOutlinePaint(i, Color.BLACK); } renderer.setMeanVisible(false); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("SansSerif", Font.BOLD, 10); //ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jchart = new JFreeChart("Assotiation Rules Measures - BoxPlot", font, plot, true); //StandardChartTheme.createLegacyTheme().apply(jchart); int width = 640 * 2; /* Width of the image */ int height = 480 * 2; /* Height of the image */ // JPEG File chart = new File( outName + "_" + measureName + "_boxplot.jpg" ); ChartUtilities.saveChartAsJPEG( chart , jchart , width , height ); // SVG SVGGraphics2D g2 = new SVGGraphics2D(width, height); Rectangle r = new Rectangle(0, 0, width, height); jchart.draw(g2, r); File BarChartSVG = new File( outName + "_" + measureName + "_boxplot.svg" ); SVGUtils.writeToSVG(BarChartSVG, g2.getSVGElement()); } }
/** * Check to ensure that this class implements PublicCloneable. */ public void testPublicCloneable() { BoxAndWhiskerToolTipGenerator g1 = new BoxAndWhiskerToolTipGenerator(); assertTrue(g1 instanceof PublicCloneable); }
public Evaluation(){ String[] nameOfTestInstances = {"att48","brg180","ch150","gr202"}; int[] numberOfTestRuns = {100,100,50,20}; int[] timeLimits = {1,2,15,120}; LinkedList<Double> ilsResults = new LinkedList<Double>(); LinkedList<Double> memeResults = new LinkedList<Double>(); final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); try { for(int j = 0; j < nameOfTestInstances.length; j++) { // dataset.clear(); for(int i = 0; i<numberOfTestRuns[j]; i++) { String[] arguments = {nameOfTestInstances[j], String.valueOf(timeLimits[j]), String.valueOf(50), "noDiagrams"}; double[] results = TSP_Main.main(arguments); ilsResults.add(results[0]); memeResults.add(results[1]); } dataset.add(ilsResults, "Iterated Local Search", nameOfTestInstances[j]); dataset.add(memeResults, "Memetic Algorithm", nameOfTestInstances[j]); ilsResults.clear(); memeResults.clear(); } final CategoryAxis xAxis = new CategoryAxis("Name of TSPLIB instance"); final NumberAxis yAxis = new NumberAxis("deviation from optimum in %"); // yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); // renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); renderer.setMeanVisible(false); renderer.setMaximumBarWidth(10); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); final NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setRange(Range.expandToInclude(axis.getRange(), -0.2)); final JFreeChart chart = new JFreeChart( "Comparison of ILS and Memetic Algorithm", new Font("SansSerif", Font.BOLD, 16), plot, true ); final ChartPanel chartPanel = new ChartPanel(chart); // chartPanel.setPreferredSize(new java.awt.Dimension(900, 540)); ChartUtilities.saveChartAsJPEG(new File("evaluation"), chart, 500, 400); setContentPane(chartPanel); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }