List of usage examples for org.jfree.chart JFreeChart JFreeChart
public JFreeChart(String title, Font titleFont, Plot plot, boolean createLegend)
From source file:org.jfree.chart.demo.OverlaidCategoryChartDemo.java
/** * Creates a new demo.// w w w.j a va 2 s . c o m * * @param title the frame title. */ public OverlaidCategoryChartDemo(String title) { super(title); DefaultIntervalCategoryDataset barData = null; double[][] lows = { { -.0315, .0159, .0306, .0453, .0557 } }; double[][] highs = { { .1931, .1457, .1310, .1163, .1059 } }; barData = new DefaultIntervalCategoryDataset(lows, highs); double[][] vals = { { 0.0808, 0.0808, 0.0808, 0.0808, 0.0808 } }; CategoryDataset dotData = DatasetUtilities.createCategoryDataset("Series ", "Category ", vals); double[][] lineVals = new double[4][5]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 5; j++) { lineVals[i][j] = (Math.random() * 0.56) - 0.18; } } CategoryDataset lineData = DatasetUtilities.createCategoryDataset("Series ", "Category ", lineVals); String ctitle = "Strategie Sicherheit"; String xTitle = "Zeitraum (in Jahren)"; String yTitle = "Performance"; CategoryAxis xAxis = new CategoryAxis(xTitle); xAxis.setLabelFont(titleFont); xAxis.setTickLabelFont(labelFont); xAxis.setTickMarksVisible(false); NumberAxis yAxis = new NumberAxis(yTitle); yAxis.setLabelFont(titleFont); yAxis.setTickLabelFont(labelFont); yAxis.setRange(-0.2, 0.4); DecimalFormat formatter = new DecimalFormat("0.##%"); yAxis.setTickUnit(new NumberTickUnit(0.05, formatter)); IntervalBarRenderer barRenderer = new IntervalBarRenderer(); barRenderer.setItemLabelsVisible(Boolean.TRUE); CategoryPlot plot = new CategoryPlot(barData, xAxis, yAxis, barRenderer); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); plot.setBackgroundPaint(Color.lightGray); plot.setOutlinePaint(Color.black); LineAndShapeRenderer dotRenderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES); dotRenderer.setItemLabelsVisible(Boolean.TRUE); plot.setSecondaryDataset(0, dotData); plot.setSecondaryRenderer(0, dotRenderer); LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES_AND_LINES); plot.setSecondaryDataset(1, lineData); plot.setSecondaryRenderer(1, lineRenderer); this.chart = new JFreeChart(ctitle, titleFont, plot, false); this.chart.setBackgroundPaint(Color.white); ChartPanel chartPanel = new ChartPanel(this.chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:OverlaidXYPlotDemo2.java
/** * Creates an overlaid chart./*www.ja v a 2 s . c o 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 www. ja v a 2 s . co m 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:GenAppStoreSales.java
/** * Creates a chart.//from ww w . j a v a 2 s.c o m * * @return A chart. */ private static JFreeChart createChart(ArrayList<String> cLabels, ArrayList<ArrayList<Integer>> cUnits) { CategoryDataset dataset1 = createDataset1(cLabels, cUnits); NumberAxis rangeAxis1 = new NumberAxis("Value"); rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); LineAndShapeRenderer renderer1 = new LineAndShapeRenderer(); renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); CategoryPlot subplot1 = new CategoryPlot(dataset1, null, rangeAxis1, renderer1); subplot1.setDomainGridlinesVisible(true); CategoryDataset dataset2 = createDataset2(cLabels, cUnits); NumberAxis rangeAxis2 = new NumberAxis("Value"); rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer renderer2 = new BarRenderer(); renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); CategoryPlot subplot2 = new CategoryPlot(dataset2, null, rangeAxis2, renderer2); subplot2.setDomainGridlinesVisible(true); CategoryAxis domainAxis = new CategoryAxis("Time"); CombinedCategoryPlot plot = new CombinedCategoryPlot(domainAxis, new NumberAxis("Units")); plot.add(subplot1, 2); plot.add(subplot2, 1); JFreeChart result = new JFreeChart(chartTitle, new Font("SansSerif", Font.BOLD, 22), plot, true); return result; }
From source file:GeMSE.Visualization.ElbowPlot.java
public void Plot(ArrayList<Double[]> pvData, ArrayList<Double[]> dData, int cut) { double maxY = 0; float[] secYColor = new float[3]; Color.RGBtoHSB(153, 245, 255, secYColor); float[] priYColor = new float[3]; Color.RGBtoHSB(255, 255, 255, priYColor); float[] cutColor = new float[3]; Color.RGBtoHSB(255, 255, 0, cutColor); //create the series - add some dummy data XYSeries pvSeries = new XYSeries("Percentage of variance "); for (int i = 1; i < pvData.size(); i++) { pvSeries.add(pvData.get(i)[0], pvData.get(i)[1]); maxY = Math.max(maxY, pvData.get(i)[1]); }// w w w. ja va 2 s .c om XYSeries dSeries = new XYSeries("Percentage of differences between slopes "); for (int i = 0; i < dData.size(); i++) dSeries.add(dData.get(i)[0], dData.get(i)[1]); XYSeries cutSeries = new XYSeries("Cut "); cutSeries.add(cut, 0.0); cutSeries.add(cut, maxY); //create the datasets XYSeriesCollection pvDataSeries = new XYSeriesCollection(); pvDataSeries.addSeries(pvSeries); XYSeriesCollection cutDataSeries = new XYSeriesCollection(); cutDataSeries.addSeries(cutSeries); XYSeriesCollection dDataSeries = new XYSeriesCollection(); dDataSeries.addSeries(dSeries); //construct the plot XYPlot plot = new XYPlot(); plot.setDataset(0, pvDataSeries); plot.setDataset(1, cutDataSeries); plot.setDataset(2, dDataSeries); // use XYSplineRenderer if you want to smooth the lines. XYLineAndShapeRenderer pvRenderer = new XYLineAndShapeRenderer(); pvRenderer.setSeriesPaint(0, Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2])); BasicStroke dstroke = new BasicStroke(2.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 1.0f, 10.0f }, 0.0f); XYLineAndShapeRenderer dRenderer = new XYLineAndShapeRenderer(); dRenderer.setSeriesPaint(0, Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2])); dRenderer.setSeriesStroke(0, dstroke); BasicStroke cutStoke = new BasicStroke(4); // use XYSplineRenderer if you want to smooth the lines. //XYSplineRenderer cutRenderer = new XYSplineRenderer(); XYLineAndShapeRenderer cutRenderer = new XYLineAndShapeRenderer(); cutRenderer.setSeriesPaint(0, Color.getHSBColor(cutColor[0], cutColor[1], cutColor[2])); cutRenderer.setSeriesStroke(0, cutStoke); plot.setRenderer(0, pvRenderer); plot.setRenderer(1, cutRenderer); plot.setRenderer(2, dRenderer); plot.setRangeAxis(0, new NumberAxis("\n\nPercentage of Variance")); plot.setRangeAxis(1, new NumberAxis("Percentage of Difference Between Slopes")); plot.setDomainAxis(new NumberAxis("Number of Clusters\n\n")); //Map the data to the appropriate axis plot.mapDatasetToRangeAxis(0, 0); plot.mapDatasetToRangeAxis(1, 0); plot.mapDatasetToRangeAxis(2, 1); float[] hsbValues = new float[3]; Color.RGBtoHSB(16, 23, 67, hsbValues); plot.setBackgroundPaint(Color.getHSBColor(hsbValues[0], hsbValues[1], hsbValues[2])); Font axisLabelFont = new Font("Dialog", Font.PLAIN, 14); Font axisTickLabelFont = new Font("Dialog", Font.PLAIN, 12); Font legendFont = new Font("Dialog", Font.PLAIN, 14); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); plot.getDomainAxis().setTickLabelPaint(Color.white); plot.getDomainAxis().setLabelPaint(Color.white); plot.getDomainAxis().setLabelFont(axisLabelFont); plot.getDomainAxis().setTickLabelFont(axisTickLabelFont); plot.getRangeAxis().setTickLabelPaint(Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2])); plot.getRangeAxis().setLabelPaint(Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2])); plot.getRangeAxis().setLabelFont(axisLabelFont); plot.getRangeAxis().setTickLabelFont(axisTickLabelFont); plot.getRangeAxis(1).setTickLabelPaint(Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2])); plot.getRangeAxis(1).setLabelPaint(Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2])); plot.getRangeAxis(1).setLabelFont(axisLabelFont); plot.getRangeAxis(1).setTickLabelFont(axisTickLabelFont); //generate the chart JFreeChart chart = new JFreeChart("\nSuggested number of clusters determined using Elbow method", getFont(), plot, true); chart.getTitle().setPaint(Color.white); chart.getLegend().setBackgroundPaint(Color.black); chart.getLegend().setItemPaint(Color.white); chart.getLegend().setPosition(RectangleEdge.BOTTOM); chart.getLegend().setItemFont(legendFont); float[] hsbValues2 = new float[3]; Color.RGBtoHSB(36, 43, 87, hsbValues2); chart.setBackgroundPaint(Color.getHSBColor(hsbValues2[0], hsbValues2[1], hsbValues2[2])); JPanel chartPanel = new ChartPanel(chart); GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); chartPanel.setPreferredSize( new java.awt.Dimension((int) Math.round((gd.getDisplayMode().getWidth() * 1.5) / 3.0), (int) Math.round((gd.getDisplayMode().getHeight() * 1.5) / 3.0))); setContentPane(chartPanel); }
From source file:com.redhat.thermostat.byteman.chart.swing.SwingBarChart.java
private JFreeChart createChart(Collection<PlotRecord> records) { // data//from ww w .java 2 s. c o 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/* w w w . j av a 2s.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: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)"; }/*ww w. j av a2s . 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); } }
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 w w w . j av a 2s. c o m 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.jfree.chart.demo.WaterfallChartDemo2.java
/** * Returns the chart.//from w w w .ja v a 2s. c om * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final CategoryAxis xAxis = new CategoryAxis("Category"); final NumberAxis yAxis = new NumberAxis("$ in Thousands"); yAxis.setLowerMargin(0.10); yAxis.setUpperMargin(0.10); // create a custom tick unit collection... final DecimalFormat formatter = new DecimalFormat("##,###"); formatter.setNegativePrefix("("); formatter.setNegativeSuffix(")"); final TickUnits standardUnits = new TickUnits(); standardUnits.add(new NumberTickUnit(200, formatter)); standardUnits.add(new NumberTickUnit(500, formatter)); standardUnits.add(new NumberTickUnit(1000, formatter)); standardUnits.add(new NumberTickUnit(2000, formatter)); standardUnits.add(new NumberTickUnit(5000, formatter)); yAxis.setStandardTickUnits(standardUnits); // **************************************************************************** // * 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. * // **************************************************************************** final DecimalFormat labelFormatter = new DecimalFormat("##,###"); labelFormatter.setNegativePrefix("("); labelFormatter.setNegativeSuffix(")"); final WaterfallBarRenderer renderer = new WaterfallBarRenderer(); // renderer.setLabelGenerator( // new StandardCategoryLabelGenerator("{2}", labelFormatter) // ); renderer.setItemLabelsVisible(Boolean.TRUE); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); final ValueMarker baseline = new ValueMarker(0.0); baseline.setPaint(Color.blue); baseline.setStroke(new BasicStroke(1.1f)); plot.addRangeMarker(baseline, Layer.FOREGROUND); final JFreeChart chart = new JFreeChart("OM WaterFall Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(Color.white); return chart; }