/** * Creates a vertical 3D-effect bar chart with default settings. * * @param title the chart title. * @param categoryAxisLabel the label for the category axis. * @param valueAxisLabel the label for the value axis. * @param data the dataset for the chart. * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * @return a vertical 3D-effect bar chart. */ public static JFreeChart createBarChart3D( String title, java.awt.Font titleFont, String categoryAxisLabel, String valueAxisLabel, CategoryDataset data, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls, CategoryURLGenerator urlGenerator) { CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel); BarRenderer3D renderer = new BarRenderer3D(); // renderer.setLabelGenerator(new StandardCategoryLabelGenerator()); if (tooltips) { renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setItemURLGenerator(urlGenerator); } CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); plot.setForegroundAlpha(0.75f); JFreeChart chart = new JFreeChart(title, titleFont, plot, legend); return chart; }
/** * Creates a stacked area chart with default settings. * * @param title the chart title. * @param categoryAxisLabel the label for the category axis. * @param valueAxisLabel the label for the value axis. * @param data the dataset for the chart. * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * @return an area chart. */ public static JFreeChart createStackedAreaChart( String title, java.awt.Font titleFont, String categoryAxisLabel, String valueAxisLabel, CategoryDataset data, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls, CategoryURLGenerator urlGenerator) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); StackedAreaRenderer renderer = new StackedAreaRenderer(); if (tooltips) { renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setItemURLGenerator(urlGenerator); } CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, titleFont, plot, legend); return chart; }
private CategoryPlot createBarChartPlot( DefaultCategoryDataset dataset, String yAxisLabel, NumberFormat yAxisNumberFormat) { CategoryAxis xAxis = new CategoryAxis("Data"); xAxis.setCategoryMargin(0.40); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setNumberFormatOverride(yAxisNumberFormat); BarRenderer renderer = createBarChartRenderer(yAxisNumberFormat); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); return plot; }
private void writeSubSingleBenchmarkScoreCharts() { subSingleBenchmarkAggregationChartFileMap = new HashMap<ProblemBenchmarkResult, List<File>>(); CategoryAxis xAxis = new CategoryAxis("Solver Configurations"); NumberAxis yAxis = new NumberAxis("Scores distribution of single benchmark runs"); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); yAxis.setAutoRangeIncludesZero(false); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer() { @Override public int getRowCount() { // TODO: HACK for https://issues.jboss.org/browse/PLANNER-429 center // plotted boxes to x axis labels return 1; } }; renderer.setFillBox(true); renderer.setUseOutlinePaintForWhiskers(true); renderer.setMedianVisible(true); renderer.setMeanVisible(false); renderer.setItemMargin(0.0); for (ProblemBenchmarkResult problemBenchmarkResult : plannerBenchmarkResult.getUnifiedProblemBenchmarkResultList()) { List<? extends BoxAndWhiskerCategoryDataset> datasetList = generateSubSingleBenchmarkScoreSummary(problemBenchmarkResult); List<File> chartFileList = new ArrayList<File>(datasetList.size()); int scoreLevelIndex = 0; for (BoxAndWhiskerCategoryDataset dataset : datasetList) { CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart( problemBenchmarkResult + " (level " + scoreLevelIndex + ") single benchmark runs score distribution", JFreeChart.DEFAULT_TITLE_FONT, plot, true); chartFileList.add( writeChartToImageFile( chart, "SubSingleSummary" + problemBenchmarkResult.getAnchorId() + "Level" + scoreLevelIndex)); scoreLevelIndex++; } subSingleBenchmarkAggregationChartFileMap.put(problemBenchmarkResult, chartFileList); } }
/** * Creates a chart. * * @param dataset a dataset. * @return A chart. */ private JFreeChart createChart(Gantt gantt, IntervalCategoryDataset dataset) { JFreeChart chart = ChartFactory.createGanttChart( "Solution Gantt", // title "Operators", // x-axis label "Time", // y-axis label null, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); CategoryPlot plot = (CategoryPlot) chart.getPlot(); Paint p = getBackgroundColorGradient(); chart.setBackgroundPaint(p); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.black); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setOrientation(PlotOrientation.HORIZONTAL); DateAxis xaxis = (DateAxis) plot.getRangeAxis(); xaxis.setDateFormatOverride(new VertexDateFormat()); xaxis.setPositiveArrowVisible(true); DefaultDrawingSupplier d = new DefaultDrawingSupplier(); plot.setDrawingSupplier(d); GanttRenderer ren = new MyGanttRenderer(); for (GanttElement element : gantt.getElementSet()) { ((MyGanttRenderer) ren).addColor(element.getTitle(), element.getColor()); } ren.setSeriesItemLabelsVisible(0, false); ren.setSeriesVisibleInLegend(0, false); ren.setSeriesItemLabelGenerator(0, new IntervalCategoryItemLabelGenerator()); ren.setSeriesToolTipGenerator(0, new MapperGanttToolTipGenerator()); ren.setAutoPopulateSeriesShape(false); plot.setRenderer(ren); plot.setDataset(dataset); return chart; }
/** * Updates the plot properties to match the properties defined on the panel. * * @param plot The plot. */ public void updatePlotProperties(Plot plot) { // set the plot properties... plot.setBackgroundPaint(SWTUtils.toAwtColor(getBackgroundPaint())); plot.setOutlinePaint(SWTUtils.toAwtColor(getOutlinePaint())); plot.setOutlineStroke(getOutlineStroke()); // set the axis properties if (this.domainAxisPropertyPanel != null) { Axis domainAxis = null; if (plot instanceof CategoryPlot) { CategoryPlot p = (CategoryPlot) plot; domainAxis = p.getDomainAxis(); } else if (plot instanceof XYPlot) { XYPlot p = (XYPlot) plot; domainAxis = p.getDomainAxis(); } if (domainAxis != null) this.domainAxisPropertyPanel.setAxisProperties(domainAxis); } if (this.rangeAxisPropertyPanel != null) { Axis rangeAxis = null; if (plot instanceof CategoryPlot) { CategoryPlot p = (CategoryPlot) plot; rangeAxis = p.getRangeAxis(); } else if (plot instanceof XYPlot) { XYPlot p = (XYPlot) plot; rangeAxis = p.getRangeAxis(); } if (rangeAxis != null) this.rangeAxisPropertyPanel.setAxisProperties(rangeAxis); } if (this.plotAppearance.getPlotOrientation() != null) { if (plot instanceof CategoryPlot) { CategoryPlot p = (CategoryPlot) plot; p.setOrientation(this.plotAppearance.getPlotOrientation()); } else if (plot instanceof XYPlot) { XYPlot p = (XYPlot) plot; p.setOrientation(this.plotAppearance.getPlotOrientation()); } } }
/** * Creates a stacked vertical bar chart with default settings. * * @param title the chart title. * @param categoryAxisLabel the label for the category axis. * @param valueAxisLabel the label for the value axis. * @param data the dataset for the chart. * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * @return a stacked vertical bar chart. */ public static JFreeChart createStackedBarChart3D( String title, java.awt.Font titleFont, String categoryAxisLabel, String valueAxisLabel, CategoryDataset data, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls, CategoryURLGenerator urlGenerator) { // create the axes... CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel); // create the renderer... CategoryItemRenderer renderer = new StackedBarRenderer3D(); CategoryToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = new StandardCategoryToolTipGenerator(); } if (urls) { renderer.setItemURLGenerator(urlGenerator); } renderer.setToolTipGenerator(toolTipGenerator); // create the plot... CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); // create the chart... JFreeChart chart = new JFreeChart(title, titleFont, plot, legend); return chart; }
/** * Starting point for the demo. * * @param args ignored. */ public static void main(final String[] args) { // create a chart final double[][] data = new double[][] { {56.0, -12.0, 34.0, 76.0, 56.0, 100.0, 67.0, 45.0}, {37.0, 45.0, 67.0, 25.0, 34.0, 34.0, 100.0, 53.0}, {43.0, 54.0, 34.0, 34.0, 87.0, 64.0, 73.0, 12.0} }; final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", data); JFreeChart chart = null; final boolean drilldown = true; if (drilldown) { final CategoryAxis categoryAxis = new CategoryAxis("Category"); final ValueAxis valueAxis = new NumberAxis("Value"); final BarRenderer renderer = new BarRenderer(); renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); renderer.setItemURLGenerator(new StandardCategoryURLGenerator("bar_chart_detail.jsp")); final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); chart = new JFreeChart("Bar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } else { chart = ChartFactory.createBarChart( "Vertical Bar Chart", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, false); } chart.setBackgroundPaint(java.awt.Color.white); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // save it to an image try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("barchart100.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); // write an HTML page incorporating the image with an image map final File file2 = new File("barchart100.html"); final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2)); final PrintWriter writer = new PrintWriter(out); writer.println("<HTML>"); writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>"); writer.println("<BODY>"); ChartUtilities.writeImageMap(writer, "chart", info, true); writer.println( "<IMG SRC=\"barchart100.png\" " + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">"); writer.println("</BODY>"); writer.println("</HTML>"); writer.close(); } catch (IOException e) { System.out.println(e.toString()); } }
/** * Updates the plot properties to match the properties defined on the panel. * * @param plot The plot. */ public void updatePlotProperties(Plot plot) { // set the plot properties... plot.setOutlinePaint(getOutlinePaint()); plot.setOutlineStroke(getOutlineStroke()); plot.setBackgroundPaint(getBackgroundPaint()); plot.setInsets(getPlotInsets()); // then the axis properties... if (this.domainAxisPropertyPanel != null) { Axis domainAxis = null; if (plot instanceof CategoryPlot) { CategoryPlot p = (CategoryPlot) plot; domainAxis = p.getDomainAxis(); } else if (plot instanceof XYPlot) { XYPlot p = (XYPlot) plot; domainAxis = p.getDomainAxis(); } if (domainAxis != null) { this.domainAxisPropertyPanel.setAxisProperties(domainAxis); } } if (this.rangeAxisPropertyPanel != null) { Axis rangeAxis = null; if (plot instanceof CategoryPlot) { CategoryPlot p = (CategoryPlot) plot; rangeAxis = p.getRangeAxis(); } else if (plot instanceof XYPlot) { XYPlot p = (XYPlot) plot; rangeAxis = p.getRangeAxis(); } else if (plot instanceof PolarPlot) { PolarPlot p = (PolarPlot) plot; rangeAxis = p.getAxis(); } if (rangeAxis != null) { this.rangeAxisPropertyPanel.setAxisProperties(rangeAxis); } } if (this.plotOrientation != null) { if (plot instanceof CategoryPlot) { CategoryPlot p = (CategoryPlot) plot; p.setOrientation(this.plotOrientation); } else if (plot instanceof XYPlot) { XYPlot p = (XYPlot) plot; p.setOrientation(this.plotOrientation); } } if (this.drawLines != null) { if (plot instanceof CategoryPlot) { CategoryPlot p = (CategoryPlot) plot; CategoryItemRenderer r = p.getRenderer(); if (r instanceof LineAndShapeRenderer) { ((LineAndShapeRenderer) r).setLinesVisible(this.drawLines.booleanValue()); } } else if (plot instanceof XYPlot) { XYPlot p = (XYPlot) plot; XYItemRenderer r = p.getRenderer(); if (r instanceof StandardXYItemRenderer) { ((StandardXYItemRenderer) r).setPlotLines(this.drawLines.booleanValue()); } } } if (this.drawShapes != null) { if (plot instanceof CategoryPlot) { CategoryPlot p = (CategoryPlot) plot; CategoryItemRenderer r = p.getRenderer(); if (r instanceof LineAndShapeRenderer) { ((LineAndShapeRenderer) r).setShapesVisible(this.drawShapes.booleanValue()); } } else if (plot instanceof XYPlot) { XYPlot p = (XYPlot) plot; XYItemRenderer r = p.getRenderer(); if (r instanceof StandardXYItemRenderer) { ((StandardXYItemRenderer) r).setBaseShapesVisible(this.drawShapes.booleanValue()); } } } // dmo: added this panel for colorbar control. (start dmo additions) if (this.colorBarAxisPropertyPanel != null) { ColorBar colorBar = null; if (plot instanceof ContourPlot) { ContourPlot p = (ContourPlot) plot; colorBar = p.getColorBar(); } if (colorBar != null) { this.colorBarAxisPropertyPanel.setAxisProperties(colorBar); } } // dmo: (end dmo additions) }
public static JFreeChart createChart() { DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset(); defaultcategorydataset.addValue(1.0D, "S1", "Category 1"); defaultcategorydataset.addValue(4D, "S1", "Category 2"); defaultcategorydataset.addValue(3D, "S1", "Category 3"); defaultcategorydataset.addValue(5D, "S1", "Category 4"); defaultcategorydataset.addValue(5D, "S1", "Category 5"); defaultcategorydataset.addValue(7D, "S1", "Category 6"); defaultcategorydataset.addValue(7D, "S1", "Category 7"); defaultcategorydataset.addValue(8D, "S1", "Category 8"); defaultcategorydataset.addValue(5D, "S2", "Category 1"); defaultcategorydataset.addValue(7D, "S2", "Category 2"); defaultcategorydataset.addValue(6D, "S2", "Category 3"); defaultcategorydataset.addValue(8D, "S2", "Category 4"); defaultcategorydataset.addValue(4D, "S2", "Category 5"); defaultcategorydataset.addValue(4D, "S2", "Category 6"); defaultcategorydataset.addValue(2D, "S2", "Category 7"); defaultcategorydataset.addValue(1.0D, "S2", "Category 8"); StandardCategoryItemLabelGenerator standardcategoryitemlabelgenerator = new StandardCategoryItemLabelGenerator(); BarRenderer barrenderer = new BarRenderer(); barrenderer.setBaseItemLabelGenerator(standardcategoryitemlabelgenerator); barrenderer.setBaseItemLabelsVisible(true); CategoryPlot categoryplot = new CategoryPlot(); categoryplot.setDataset(defaultcategorydataset); categoryplot.setRenderer(barrenderer); categoryplot.setDomainAxis(new CategoryAxis("Category")); categoryplot.setRangeAxis(new NumberAxis("Value")); categoryplot.setOrientation(PlotOrientation.VERTICAL); categoryplot.setRangeGridlinesVisible(true); categoryplot.setDomainGridlinesVisible(true); DefaultCategoryDataset defaultcategorydataset1 = new DefaultCategoryDataset(); defaultcategorydataset1.addValue(9D, "T1", "Category 1"); defaultcategorydataset1.addValue(7D, "T1", "Category 2"); defaultcategorydataset1.addValue(2D, "T1", "Category 3"); defaultcategorydataset1.addValue(6D, "T1", "Category 4"); defaultcategorydataset1.addValue(6D, "T1", "Category 5"); defaultcategorydataset1.addValue(9D, "T1", "Category 6"); defaultcategorydataset1.addValue(5D, "T1", "Category 7"); defaultcategorydataset1.addValue(4D, "T1", "Category 8"); LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer(); categoryplot.setDataset(1, defaultcategorydataset1); categoryplot.setRenderer(1, lineandshaperenderer); NumberAxis numberaxis = new NumberAxis("Axis 2"); categoryplot.setRangeAxis(1, numberaxis); DefaultCategoryDataset defaultcategorydataset2 = new DefaultCategoryDataset(); defaultcategorydataset2.addValue(94D, "R1", "Category 1"); defaultcategorydataset2.addValue(75D, "R1", "Category 2"); defaultcategorydataset2.addValue(22D, "R1", "Category 3"); defaultcategorydataset2.addValue(74D, "R1", "Category 4"); defaultcategorydataset2.addValue(83D, "R1", "Category 5"); defaultcategorydataset2.addValue(9D, "R1", "Category 6"); defaultcategorydataset2.addValue(23D, "R1", "Category 7"); defaultcategorydataset2.addValue(98D, "R1", "Category 8"); categoryplot.setDataset(2, defaultcategorydataset2); LineAndShapeRenderer lineandshaperenderer1 = new LineAndShapeRenderer(); categoryplot.setRenderer(2, lineandshaperenderer1); categoryplot.mapDatasetToRangeAxis(2, 1); categoryplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); categoryplot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); JFreeChart jfreechart = new JFreeChart(categoryplot); jfreechart.setTitle("Overlaid Bar Chart"); return jfreechart; }