List of usage examples for org.jfree.chart JFreeChart DEFAULT_TITLE_FONT
Font DEFAULT_TITLE_FONT
To view the source code for org.jfree.chart JFreeChart DEFAULT_TITLE_FONT.
Click Source Link
From source file:edu.gmu.cs.sim.util.media.chart.BoxPlotGenerator.java
protected void buildChart() { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); // we build the chart manually rather than using ChartFactory // because we need to customize the getDataRange method below CategoryAxis categoryAxis = new CategoryAxis(""); NumberAxis valueAxis = new NumberAxis("Untitled Y Axis"); valueAxis.setAutoRangeIncludesZero(false); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer) { // Customizing this method in order to provide a bit of // vertical buffer. Otherwise the bar chart box gets drawn // slightly off-chart, which looks really bad. public Range getDataRange(ValueAxis axis) { Range range = super.getDataRange(axis); if (range == null) { return null; }/*from w w w . j a v a 2 s.c o m*/ final double EXTRA_PERCENTAGE = 0.02; return Range.expand(range, EXTRA_PERCENTAGE, EXTRA_PERCENTAGE); } }; chart = new JFreeChart("Untitled Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false); ChartFactory.getChartTheme().apply(chart); chart.setAntiAlias(true); chartPanel = buildChartPanel(chart); setChartPanel(chartPanel); // this must come last because the chart must exist for us to set its dataset setSeriesDataset(dataset); }
From source file:r2d2e.solution.moduloteste.teste.GraficoD2.java
/** * Creates a combined chart./*from w ww . j ava 2 s. co m*/ * * @return the combined chart. */ private JFreeChart createCombinedChart() { // create subplot 1... final XYDataset data1 = collection; final XYItemRenderer renderer1 = new StandardXYItemRenderer(); final NumberAxis rangeAxis1 = new NumberAxis("Nvel (cm)"); final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); /* final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0); annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation.setRotationAngle(Math.PI / 4.0); subplot1.addAnnotation(annotation); */ // create subplot 2... final XYDataset data2 = collection2; final XYItemRenderer renderer2 = new StandardXYItemRenderer(); final NumberAxis rangeAxis2 = new NumberAxis("Tenso (volts)"); final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2); subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // create subplot 3... final XYDataset data3 = collection3; final XYItemRenderer renderer3 = new StandardXYItemRenderer(); final NumberAxis rangeAxis3 = new NumberAxis("Tenso (volts)"); final XYPlot subplot3 = new XYPlot(data3, null, rangeAxis3, renderer3); subplot3.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // parent plot... final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Tempo")); plot.setGap(10.0); // add the subplots... plot.add(subplot1, 1); plot.add(subplot2, 1); plot.add(subplot3, 1); plot.setOrientation(PlotOrientation.VERTICAL); // return a new chart containing the overlaid plot... return new JFreeChart("Grficos", JFreeChart.DEFAULT_TITLE_FONT, plot, true); }
From source file:org.optaplanner.benchmark.impl.statistic.improvingsteppercentage.ImprovingStepPercentageProblemStatistic.java
@Override protected void writeGraphStatistic() { Map<Class<? extends Move>, XYPlot> plots = new HashMap<Class<? extends Move>, XYPlot>(); int seriesIndex = 0; for (SingleBenchmark singleBenchmark : problemBenchmark.getSingleBenchmarkList()) { Map<Class<? extends Move>, XYSeries> seriesMap = new HashMap<Class<? extends Move>, XYSeries>(); // No direct ascending lines between 2 points, but a stepping line instead XYItemRenderer renderer = new XYStepRenderer(); if (singleBenchmark.isSuccess()) { ImprovingStepPercentageSingleStatistic singleStatistic = (ImprovingStepPercentageSingleStatistic) singleBenchmark .getSingleStatistic(problemStatisticType); for (Map.Entry<Class<? extends Move>, List<ImprovingStepPercentageSingleStatisticPoint>> entry : singleStatistic .getPointLists().entrySet()) { Class<? extends Move> moveClass = entry.getKey(); if (!seriesMap.containsKey(moveClass)) { seriesMap.put(moveClass, new XYSeries(singleBenchmark.getSolverBenchmark().getNameWithFavoriteSuffix())); }/*from w w w.ja va 2s . c o m*/ XYSeries series = seriesMap.get(moveClass); for (ImprovingStepPercentageSingleStatisticPoint point : entry.getValue()) { long timeMillisSpend = point.getTimeMillisSpend(); double ratio = point.getRatio(); series.add(timeMillisSpend, ratio); } } } if (singleBenchmark.getSolverBenchmark().isFavorite()) { // Make the favorite more obvious renderer.setSeriesStroke(0, new BasicStroke(2.0f)); } for (Map.Entry<Class<? extends Move>, XYSeries> entry : seriesMap.entrySet()) { Class<? extends Move> moveClass = entry.getKey(); if (!plots.containsKey(moveClass)) { plots.put(moveClass, createPlot(moveClass)); } plots.get(moveClass).setDataset(seriesIndex, new XYSeriesCollection(entry.getValue())); plots.get(moveClass).setRenderer(seriesIndex, renderer); } for (int i = 0; i < seriesMap.size(); i++) { } seriesIndex++; } graphStatisticFileMap = new LinkedHashMap<Class<? extends Move>, File>(plots.size()); for (Map.Entry<Class<? extends Move>, XYPlot> entry : plots.entrySet()) { Class<? extends Move> moveClass = entry.getKey(); JFreeChart chart = new JFreeChart(problemBenchmark.getName() + " improving step percentage " + moveClass.getSimpleName() + " statistic", JFreeChart.DEFAULT_TITLE_FONT, entry.getValue(), true); graphStatisticFileMap.put(moveClass, writeChartToImageFile(chart, problemBenchmark.getName() + "ImprovingStepPercentageStatistic-" + moveClass.getCanonicalName())); } }
From source file:org.optaplanner.benchmark.impl.statistic.movecountperstep.MoveCountPerStepProblemStatistic.java
@Override public void writeGraphFiles(BenchmarkReport benchmarkReport) { Locale locale = benchmarkReport.getLocale(); NumberAxis xAxis = new NumberAxis("Time spent"); xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale)); NumberAxis yAxis = new NumberAxis("Accepted/selected moves per step"); yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); DrawingSupplier drawingSupplier = new DefaultDrawingSupplier(); plot.setOrientation(PlotOrientation.VERTICAL); int seriesIndex = 0; for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) { XYSeries acceptedSeries = new XYSeries( singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix() + " accepted"); XYSeries selectedSeries = new XYSeries( singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix() + " selected"); XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); if (singleBenchmarkResult.isSuccess()) { MoveCountPerStepSingleStatistic singleStatistic = (MoveCountPerStepSingleStatistic) singleBenchmarkResult .getSingleStatistic(problemStatisticType); for (MoveCountPerStepStatisticPoint point : singleStatistic.getPointList()) { long timeMillisSpent = point.getTimeMillisSpent(); long acceptedMoveCount = point.getMoveCountPerStepMeasurement().getAcceptedMoveCount(); long selectedMoveCount = point.getMoveCountPerStepMeasurement().getSelectedMoveCount(); acceptedSeries.add(timeMillisSpent, acceptedMoveCount); selectedSeries.add(timeMillisSpent, selectedMoveCount); }/*from w w w .ja v a2 s . c om*/ } XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(acceptedSeries); seriesCollection.addSeries(selectedSeries); plot.setDataset(seriesIndex, seriesCollection); if (singleBenchmarkResult.getSolverBenchmarkResult().isFavorite()) { // Make the favorite more obvious renderer.setSeriesStroke(0, new BasicStroke(2.0f)); // Dashed line for selected move count renderer.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f)); } else { // Dashed line for selected move count renderer.setSeriesStroke(1, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f)); } // Render both lines in the same color Paint linePaint = drawingSupplier.getNextPaint(); renderer.setSeriesPaint(0, linePaint); renderer.setSeriesPaint(1, linePaint); plot.setRenderer(seriesIndex, renderer); seriesIndex++; } JFreeChart chart = new JFreeChart(problemBenchmarkResult.getName() + " move count per step statistic", JFreeChart.DEFAULT_TITLE_FONT, plot, true); graphFile = writeChartToImageFile(chart, problemBenchmarkResult.getName() + "MoveCountPerStepStatistic"); }
From source file:OverlaidXYPlotDemo2.java
/** * Creates an overlaid chart./*from w w w .ja va2 s .co m*/ * * @return The chart. */ private JFreeChart createOverlaidChart() { final DateAxis domainAxis = new DateAxis("Date"); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); final ValueAxis rangeAxis = new NumberAxis("Value"); // create plot... final IntervalXYDataset data1 = createDataset1(); final XYItemRenderer renderer1 = new XYBarRenderer(0.20); renderer1.setToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); final XYPlot plot = new XYPlot(data1, domainAxis, rangeAxis, renderer1); final double x = new Day(9, SerialDate.MARCH, 2002).getMiddleMillisecond(); final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", x, 10000.0); annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); plot.addAnnotation(annotation); final ValueAxis rangeAxis2 = new NumberAxis("Value 2"); plot.setRangeAxis(1, rangeAxis2); // create subplot 2... final XYDataset data2A = createDataset2A(); final XYItemRenderer renderer2A = new StandardXYItemRenderer(); renderer2A.setToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); plot.setDataset(1, data2A); plot.setRenderer(1, renderer2A); final XYDataset data2B = createDataset2B(); plot.setDataset(2, data2B); plot.setRenderer(2, new StandardXYItemRenderer()); plot.mapDatasetToRangeAxis(2, 1); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.setOrientation(PlotOrientation.VERTICAL); // return a new chart containing the overlaid plot... return new JFreeChart("Overlaid Plot Example", JFreeChart.DEFAULT_TITLE_FONT, plot, true); }
From source file:org.optaplanner.benchmark.impl.statistic.bestscore.BestScoreProblemStatistic.java
@Override public void writeGraphFiles(BenchmarkReport benchmarkReport) { List<XYPlot> plotList = new ArrayList<XYPlot>(BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE); int seriesIndex = 0; for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) { List<XYSeries> seriesList = new ArrayList<XYSeries>(BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE); // No direct ascending lines between 2 points, but a stepping line instead XYItemRenderer renderer = new XYStepRenderer(); if (singleBenchmarkResult.isSuccess()) { BestScoreSingleStatistic singleStatistic = (BestScoreSingleStatistic) singleBenchmarkResult .getSingleStatistic(problemStatisticType); for (BestScoreStatisticPoint point : singleStatistic.getPointList()) { long timeMillisSpent = point.getTimeMillisSpent(); double[] levelValues = ScoreUtils.extractLevelDoubles(point.getScore()); for (int i = 0; i < levelValues.length && i < BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE; i++) { if (i >= seriesList.size()) { seriesList.add(new XYSeries( singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix())); }//from w ww. ja v a 2s . c om seriesList.get(i).add(timeMillisSpent, levelValues[i]); } } // TODO if startingSolution is initialized and no improvement is made, a horizontal line should be shown // Draw a horizontal line from the last new best step to how long the solver actually ran long timeMillisSpent = singleBenchmarkResult.getTimeMillisSpent(); double[] bestScoreLevels = ScoreUtils.extractLevelDoubles(singleBenchmarkResult.getScore()); for (int i = 0; i < bestScoreLevels.length && i < BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE; i++) { if (i >= seriesList.size()) { seriesList.add(new XYSeries( singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix())); } seriesList.get(i).add(timeMillisSpent, bestScoreLevels[i]); } if (singleStatistic.getPointList().size() <= 1) { // Workaround for https://sourceforge.net/tracker/?func=detail&aid=3387330&group_id=15494&atid=115494 renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES); } } if (singleBenchmarkResult.getSolverBenchmarkResult().isFavorite()) { // Make the favorite more obvious renderer.setSeriesStroke(0, new BasicStroke(2.0f)); } for (int i = 0; i < seriesList.size(); i++) { if (i >= plotList.size()) { plotList.add(createPlot(benchmarkReport, i)); } plotList.get(i).setDataset(seriesIndex, new XYSeriesCollection(seriesList.get(i))); plotList.get(i).setRenderer(seriesIndex, renderer); } seriesIndex++; } graphFileList = new ArrayList<File>(plotList.size()); for (int scoreLevelIndex = 0; scoreLevelIndex < plotList.size(); scoreLevelIndex++) { JFreeChart chart = new JFreeChart( problemBenchmarkResult.getName() + " best score level " + scoreLevelIndex + " statistic", JFreeChart.DEFAULT_TITLE_FONT, plotList.get(scoreLevelIndex), true); graphFileList.add(writeChartToImageFile(chart, problemBenchmarkResult.getName() + "BestScoreStatisticLevel" + scoreLevelIndex)); } }
From source file:com.redhat.thermostat.byteman.chart.swing.SwingBarChart.java
private JFreeChart createChart(Collection<PlotRecord> records) { // data//w w w. j a v a 2 s . co m DefaultCategoryDataset ds = new DefaultCategoryDataset(); for (PlotRecord re : records) { Long label = re.getPeriodStart() + ((re.getPeriodEnd() - re.getPeriodStart()) / 2); ds.addValue(re.getValue(), re.getCategory(), label); } // chart BarRenderer3D br = new StackedBarRenderer3D(cf.rendered3dXOffset, cf.rendered3dYOffset); ZoomablePlot plot = new ZoomablePlot(zm, ds, new CategoryAxis(), new NumberAxis(), br); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false); ChartFactory.getChartTheme().apply(chart); // renderer br.setSeriesPaint(0, toColor(cf.seriesPaint0)); br.setSeriesPaint(1, toColor(cf.seriesPaint1)); br.setSeriesPaint(2, toColor(cf.seriesPaint2)); br.setSeriesPaint(3, toColor(cf.seriesPaint3)); br.setSeriesPaint(4, toColor(cf.seriesPaint4)); br.setSeriesPaint(5, toColor(cf.seriesPaint5)); br.setWallPaint(toColor(cf.wallPaint)); br.setBaseItemLabelsVisible(cf.baseItemLabelsVisible); br.setShadowVisible(cf.shadowVisible); br.setItemMargin(cf.itemMargin); // plot plot.setBackgroundPaint(toColor(cf.backgroundPaint)); plot.setBackgroundImageAlpha((float) cf.backgroundImageAlpha); plot.setDomainGridlinesVisible(cf.domainGridlinesVisible); plot.setRangeGridlinePaint(toColor(cf.rangeGridlinePaint)); // plot.getRangeAxis().setRange(new Range(ds.getMin(), ds.getMax() * 1.1)); plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.getRangeAxis().setLabel(cf.rangeAxisLabel); colorAxis(plot.getRangeAxis()); colorAxis(plot.getDomainAxis()); plot.getDomainAxis().setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI * cf.domainAxisLabelAngle)); plot.getDomainAxis().setLowerMargin(cf.domainAxisLowerMargin); plot.getDomainAxis().setUpperMargin(cf.domainAxisUpperMargin); plot.getDomainAxis().setLabel(cf.domainAxisLabel); plot.setOutlineVisible(cf.outlineVisible); return chart; }
From source file:playground.yu.utils.charts.DoubleBarChart.java
/** * @param args/*from w ww . j a v a 2 s . c o m*/ */ public static void run0(String[] args) { String chartFilename = "../matsimTests/charts/barChart.png"; BarChart chartA = new BarChart("", "", "Wegdistanz - MZ05", new String[] { "Arbeit (work)", "Rueckkehr nach Hause bzw. auswaertige Unterkunft (home)", "Freizeit (leisure)", "Einkauf (shopping)", "Ausbildung/Schule (education)", "Andere", "Geschaeftliche Taetigkeit und Dienstfahrt", "Service- und Begleitwege", "total" }); chartA.addSeries("MIV (car)", new double[] { 9.04, 33.90, 12.20, 7.15, 6.83, 6.28, 14.39, 4.48, 10.16 }); chartA.addSeries("OeV (pt)", new double[] { 10.86, 36.80, 15.04, 5.67, 10.06, 54.11, 33.04, 9.02, 12.19 }); chartA.addSeries("LV (walk)", new double[] { 1.19, 0.24, 0.81, 0.70, 2.17, 0.57, 1.93, 0.75, 1.04 }); chartA.addSeries("Andere (others)", new double[] { 18.16, 22.23, 10.78, 5.19, 0.84, 12.97, 44.90, 3.7, 11.76 }); CategoryPlot subplotA = chartA.getChart().getCategoryPlot(); BarChart chartB = new BarChart("", "", "Wegdistanz - Matsim-run698", new String[] { "Arbeit (work)", "Rueckkehr nach Hause bzw. auswaertige Unterkunft (home)", "Freizeit (leisure)", "Einkauf (shopping)", "Ausbildung/Schule (education)", "Andere", "Geschaeftliche Taetigkeit und Dienstfahrt", "Service- und Begleitwege", "total" }); chartB.addSeries("MIV (car)", new double[] { 10.71, 7.79, 6.28, 5.77, 6.65, 0, 0, 0, 8.05 }); chartB.addSeries("OeV (pt)", new double[] { 6.37, 6.10, 4.10, 4.10, 4.64, 0, 0, 0, 5.44 }); chartB.addSeries("LV (walk)", new double[] { 0.88, 0.85, 0.75, 0.75, 0.81, 0, 0, 0, 0.81 }); chartB.addSeries("Andere (others)", new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }); CategoryPlot subplotB = chartB.getChart().getCategoryPlot(); final CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot( new CategoryAxis("Verkehrszwecke/ travel destinations")); plot.add(subplotA, 1); plot.add(subplotB, 1); final JFreeChart result = new JFreeChart("MZ05 vs MATSim - mittlere Wegdistanz", JFreeChart.DEFAULT_TITLE_FONT, plot, true); try { ChartUtilities.saveChartAsPNG(new File(chartFilename), result, 1024, 768, null, true, 9); } catch (IOException e) { e.printStackTrace(); } // chartA.saveAsPng(chartFilename, 800, 600); }
From source file:de.bund.bfr.knime.pmmlite.views.chart.ChartCreator.java
public JFreeChart getChart(List<String> idsToPaint) throws ParseException, UnitException { if (varX == null || varY == null || varX.getName() == null || varY.getName() == null) { return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, new XYPlot(), showLegend); }//from www.j ava 2 s .c om NumberAxis xAxis = new NumberAxis(varX.getDisplayString()); NumberAxis yAxis = new NumberAxis(varY.getDisplayString()); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); double usedMinX = Double.POSITIVE_INFINITY; double usedMaxX = Double.NEGATIVE_INFINITY; int index = 0; List<Color> defaultColors = ChartUtils.createColorList(idsToPaint.size()); List<NamedShape> defaultShapes = ChartUtils.createShapeList(idsToPaint.size()); for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable == null) { continue; } if (plotable.getType() == Plotable.Type.BOTH || plotable.getType() == Plotable.Type.BOTH_MANY || plotable.getType() == Plotable.Type.FUNCTION || plotable.getType() == Plotable.Type.FUNCTION_SAMPLE) { double minArg = varX.to(MathUtils.nullToNan(plotable.getMinValues().get(varX.getName())), plotable.getUnits().get(varX.getName())); double maxArg = varX.to(MathUtils.nullToNan(plotable.getMaxValues().get(varX.getName())), plotable.getUnits().get(varX.getName())); if (Double.isFinite(minArg)) { usedMinX = Math.min(usedMinX, minArg); } if (Double.isFinite(maxArg)) { usedMaxX = Math.max(usedMaxX, maxArg); } } if (plotable.getType() == Plotable.Type.BOTH || plotable.getType() == Plotable.Type.BOTH_MANY) { for (Map<String, Integer> choice : plotable.getAllChoices(varX.getName())) { double[][] points = plotable.getPoints(varX, varY, choice); if (points != null) { for (int i = 0; i < points[0].length; i++) { usedMinX = Math.min(usedMinX, points[0][i]); usedMaxX = Math.max(usedMaxX, points[0][i]); } } } } if (plotable.getType() == Plotable.Type.DATASET || plotable.getType() == Plotable.Type.DATASET_MANY) { double[][] points = plotable.getPoints(varX, varY); if (points != null) { for (int i = 0; i < points[0].length; i++) { usedMinX = Math.min(usedMinX, points[0][i]); usedMaxX = Math.max(usedMaxX, points[0][i]); } } } if (plotable.getType() == Plotable.Type.FUNCTION_SAMPLE) { for (Double x : plotable.getSamples()) { if (x != null && Double.isFinite(x)) { usedMinX = Math.min(usedMinX, x); usedMaxX = Math.max(usedMaxX, x); } } } } if (Double.isInfinite(usedMinX)) { usedMinX = 0.0; } if (Double.isInfinite(usedMaxX)) { usedMaxX = 100.0; } if (varX.getName().equals(PmmUtils.TIME) || varX.getName().equals(PmmUtils.CONCENTRATION)) { usedMinX = Math.min(usedMinX, 0.0); xAxis.setAutoRangeIncludesZero(true); } else { xAxis.setAutoRangeIncludesZero(false); } if (varY.getName().equals(PmmUtils.TIME) || varY.getName().equals(PmmUtils.CONCENTRATION)) { yAxis.setAutoRangeIncludesZero(true); } else { yAxis.setAutoRangeIncludesZero(false); } if (usedMinX == usedMaxX) { usedMinX -= 1.0; usedMaxX += 1.0; } if (useManualRange && minX < maxX && minY < maxY) { usedMinX = minX; usedMaxX = maxX; xAxis.setRange(new Range(minX, maxX)); yAxis.setRange(new Range(minY, maxY)); } for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable == null) { continue; } plotable.setFunctionSteps(resolution); switch (plotable.getType()) { case DATASET: plotDataSet(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index)); break; case DATASET_MANY: plotDataSetStrict(plot, plotable, id); break; case FUNCTION: plotFunction(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX, usedMaxX); break; case FUNCTION_SAMPLE: plotFunctionSample(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX, usedMaxX); break; case BOTH: plotBoth(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX, usedMaxX); break; case BOTH_MANY: plotBothStrict(plot, plotable, id, usedMinX, usedMaxX); break; default: throw new RuntimeException("Unknown type of plotable: " + plotable.getType()); } index++; } return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, showLegend); }
From source file:org.drools.planner.benchmark.core.statistic.PlannerStatistic.java
private void writeBestScoreSummaryChart() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) { ScoreDefinition scoreDefinition = solverBenchmark.getSolverConfig().getScoreDirectorFactoryConfig() .buildScoreDefinition(); for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) { if (singleBenchmark.isSuccess()) { Score score = singleBenchmark.getScore(); Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score); String solverLabel = solverBenchmark.getName(); if (solverBenchmark.isRankingBest()) { solverLabel += " (winner)"; }/*from w w w . j av a2 s . c o m*/ String planningProblemLabel = singleBenchmark.getProblemBenchmark().getName(); dataset.addValue(scoreGraphValue, solverLabel, planningProblemLabel); } } } CategoryAxis xAxis = new CategoryAxis("Data"); xAxis.setCategoryMargin(0.40); NumberAxis yAxis = new NumberAxis("Score"); BarRenderer renderer = new BarRenderer(); ItemLabelPosition positiveItemLabelPosition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); renderer.setBasePositiveItemLabelPosition(positiveItemLabelPosition); ItemLabelPosition negativeItemLabelPosition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); renderer.setBaseNegativeItemLabelPosition(negativeItemLabelPosition); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelsVisible(true); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart("Best score summary (higher score is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); BufferedImage chartImage = chart.createBufferedImage(1024, 768); bestScoreSummaryFile = new File(plannerBenchmark.getBenchmarkReportDirectory(), "bestScoreSummary.png"); OutputStream out = null; try { out = new FileOutputStream(bestScoreSummaryFile); ImageIO.write(chartImage, "png", out); } catch (IOException e) { throw new IllegalArgumentException("Problem writing bestScoreSummaryFile: " + bestScoreSummaryFile, e); } finally { IOUtils.closeQuietly(out); } }