Example usage for org.jfree.chart JFreeChart JFreeChart

List of usage examples for org.jfree.chart JFreeChart JFreeChart

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart JFreeChart.

Prototype

public JFreeChart(String title, Font titleFont, Plot plot, boolean createLegend) 

Source Link

Document

Creates a new chart with the given title and plot.

Usage

From source file:org.optaplanner.benchmark.impl.statistic.memoryuse.MemoryUseProblemStatistic.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("Memory");
    yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    plot.setOrientation(PlotOrientation.VERTICAL);
    int seriesIndex = 0;
    for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) {
        XYSeries usedSeries = new XYSeries(
                singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix() + " used");
        // TODO enable max memory, but in the same color as used memory, but with a dotted line instead
        //            XYSeries maxSeries = new XYSeries(
        //                    singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix() + " max");
        XYItemRenderer renderer = new XYLineAndShapeRenderer();
        if (singleBenchmarkResult.isSuccess()) {
            MemoryUseSingleStatistic singleStatistic = (MemoryUseSingleStatistic) singleBenchmarkResult
                    .getSingleStatistic(problemStatisticType);
            for (MemoryUseStatisticPoint point : singleStatistic.getPointList()) {
                long timeMillisSpent = point.getTimeMillisSpent();
                MemoryUseMeasurement memoryUseMeasurement = point.getMemoryUseMeasurement();
                usedSeries.add(timeMillisSpent, memoryUseMeasurement.getUsedMemory());
                //                    maxSeries.add(timeMillisSpent, memoryUseMeasurement.getMaxMemory());
            }//from ww w.  j a  v a2  s  .c  om
        }
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(usedSeries);
        //            seriesCollection.addSeries(maxSeries);
        plot.setDataset(seriesIndex, seriesCollection);

        if (singleBenchmarkResult.getSolverBenchmarkResult().isFavorite()) {
            // Make the favorite more obvious
            renderer.setSeriesStroke(0, new BasicStroke(2.0f));
            //                renderer.setSeriesStroke(1, new BasicStroke(2.0f));
        }
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;
    }
    JFreeChart chart = new JFreeChart(problemBenchmarkResult.getName() + " memory use statistic",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    graphFile = writeChartToImageFile(chart, problemBenchmarkResult.getName() + "MemoryUseStatistic");
}

From source file:com.spotify.heroic.http.render.RenderUtils.java

private static JFreeChart buildChart(final String title, final XYDataset lineAndShape, final XYDataset interval,
        final XYItemRenderer lineAndShapeRenderer, final XYItemRenderer intervalRenderer) {
    final ValueAxis timeAxis = new DateAxis();
    timeAxis.setLowerMargin(0.02);/*w  w  w  . jav a2  s.  c o  m*/
    timeAxis.setUpperMargin(0.02);

    final NumberAxis valueAxis = new NumberAxis();
    valueAxis.setAutoRangeIncludesZero(false);

    final XYPlot plot = new XYPlot();

    plot.setDomainAxis(0, timeAxis);
    plot.setRangeAxis(0, valueAxis);

    plot.setDataset(0, lineAndShape);
    plot.setRenderer(0, lineAndShapeRenderer);

    plot.setDomainAxis(1, timeAxis);
    plot.setRangeAxis(1, valueAxis);

    plot.setDataset(1, interval);
    plot.setRenderer(1, intervalRenderer);

    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
}

From source file:net.sf.mzmine.modules.visualization.neutralloss.NeutralLossPlot.java

NeutralLossPlot(NeutralLossVisualizerWindow visualizer, NeutralLossDataSet dataset, Object xAxisType) {

    super(null, true);

    this.visualizer = visualizer;

    setBackground(Color.white);// www .j  av a2  s .  co m
    setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

    NumberFormat rtFormat = MZmineCore.getConfiguration().getRTFormat();
    NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();

    // set the X axis (retention time) properties
    NumberAxis xAxis;
    if (xAxisType.equals(NeutralLossParameters.xAxisPrecursor)) {
        xAxis = new NumberAxis("Precursor m/z");
        xAxis.setNumberFormatOverride(mzFormat);
    } else {
        xAxis = new NumberAxis("Retention time");
        xAxis.setNumberFormatOverride(rtFormat);
    }
    xAxis.setUpperMargin(0);
    xAxis.setLowerMargin(0);
    xAxis.setAutoRangeIncludesZero(false);

    // set the Y axis (intensity) properties
    NumberAxis yAxis = new NumberAxis("Neutral loss (Da)");
    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setNumberFormatOverride(mzFormat);
    yAxis.setUpperMargin(0);
    yAxis.setLowerMargin(0);

    // set the renderer properties
    defaultRenderer = new NeutralLossDataPointRenderer(false, true);
    defaultRenderer.setTransparency(0.4f);
    setSeriesColorRenderer(0, pointColor, dataPointsShape);
    setSeriesColorRenderer(1, searchPrecursorColor, dataPointsShape2);
    setSeriesColorRenderer(2, searchNeutralLossColor, dataPointsShape2);

    // tooltips
    defaultRenderer.setBaseToolTipGenerator(dataset);

    // set the plot properties
    plot = new XYPlot(dataset, xAxis, yAxis, defaultRenderer);
    plot.setBackgroundPaint(Color.white);
    plot.setRenderer(defaultRenderer);
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);

    // chart properties
    chart = new JFreeChart("", titleFont, plot, false);
    chart.setBackgroundPaint(Color.white);

    setChart(chart);

    // title
    chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    // disable maximum size (we don't want scaling)
    setMaximumDrawWidth(Integer.MAX_VALUE);
    setMaximumDrawHeight(Integer.MAX_VALUE);

    // set crosshair (selection) properties
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairPaint(crossHairColor);
    plot.setRangeCrosshairPaint(crossHairColor);
    plot.setDomainCrosshairStroke(crossHairStroke);
    plot.setRangeCrosshairStroke(crossHairStroke);

    plot.addRangeMarker(new ValueMarker(0));

    // set focusable state to receive key events
    setFocusable(true);

    // register key handlers
    GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke("SPACE"), visualizer, "SHOW_SPECTRUM");

    // add items to popup menu
    JPopupMenu popupMenu = getPopupMenu();
    popupMenu.addSeparator();

    JMenuItem highLightPrecursorRange = new JMenuItem("Highlight precursor m/z range...");
    highLightPrecursorRange.addActionListener(visualizer);
    highLightPrecursorRange.setActionCommand("HIGHLIGHT_PRECURSOR");
    popupMenu.add(highLightPrecursorRange);

    JMenuItem highLightNeutralLossRange = new JMenuItem("Highlight neutral loss m/z range...");
    highLightNeutralLossRange.addActionListener(visualizer);
    highLightNeutralLossRange.setActionCommand("HIGHLIGHT_NEUTRALLOSS");
    popupMenu.add(highLightNeutralLossRange);

}

From source file:no.uio.medicine.virsurveillance.charts.BoxAndWhiskerChart_AWT.java

public BoxAndWhiskerChart_AWT(String applicationTitle, String chartTitle, String xTitle, String yTitle,
        ArrayList<ArrayList<Float>> singleSerieDataPoints, ArrayList<String> singleSerieCategories,
        String singleSerieTitle) {

    super(applicationTitle);

    this.chartTitle = chartTitle;
    this.xAxisTitle = xTitle;
    this.yAxisTitle = yTitle;
    this.Title = applicationTitle;

    this.dataPoints = new ArrayList<>();
    this.dataPoints.add(singleSerieDataPoints);
    this.categories = new ArrayList<>();
    this.categories.add(singleSerieCategories);
    this.seriesTitles = new ArrayList<>();
    this.seriesTitles.add(singleSerieTitle);

    BoxAndWhiskerCategoryDataset dataset = (BoxAndWhiskerCategoryDataset) createDataset(this.dataPoints,
            this.categories, this.seriesTitles);

    final CategoryAxis xAxis = new CategoryAxis(xTitle);
    final NumberAxis yAxis = new NumberAxis(yTitle);
    yAxis.setAutoRangeIncludesZero(false);
    this.renderer = new BoxAndWhiskerRenderer();
    this.renderer.setFillBox(false);

    this.renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    this.plot = new CategoryPlot(dataset, xAxis, yAxis, this.renderer);

    final JFreeChart chart = new JFreeChart(chartTitle, new Font("SansSerif", Font.BOLD, 14), this.plot, true);
    chart.setBackgroundPaint(Color.white);
    this.chartPanel = new ChartPanel(chart);
    this.chartPanel.setBackground(Color.white);
    this.chartPanel.setPreferredSize(new java.awt.Dimension(1200, 500));
    setContentPane(chartPanel);//from  w w w .  j  a v a  2s  .  c  o  m
    this.setDefaultCloseOperation(HIDE_ON_CLOSE);

}

From source file:net.sf.jasperreports.components.spiderchart.SpiderChartRendererEvaluator.java

/**
 * //from   w  w  w.  jav  a2  s  .  c o m
 */
public static Renderable evaluateRenderable(JasperReportsContext jasperReportsContext,
        JRComponentElement element, SpiderChartSharedBean spiderchartBean, ChartCustomizer chartCustomizer,
        String defaultRenderType, String datasetType) {
    SpiderChartComponent chartComponent = (SpiderChartComponent) element.getComponent();
    ChartSettings chartSettings = chartComponent.getChartSettings();
    SpiderPlot plot = (SpiderPlot) chartComponent.getPlot();

    DefaultCategoryDataset dataset = null;
    StandardCategoryItemLabelGenerator labelGenerator = null;

    if (FILL_DATASET.equals(datasetType)) {
        dataset = ((FillSpiderDataset) spiderchartBean.getDataset()).getCustomDataset();
        labelGenerator = ((FillSpiderDataset) spiderchartBean.getDataset()).getLabelGenerator();
    } else {
        dataset = getSampleDataset();
        labelGenerator = new StandardCategoryItemLabelGenerator();
    }

    SpiderWebPlot spiderWebPlot = new SpiderWebPlot(dataset);

    if (plot.getAxisLineColor() != null) {
        spiderWebPlot.setAxisLinePaint(plot.getAxisLineColor());
    }
    if (plot.getAxisLineWidth() != null) {
        spiderWebPlot.setAxisLineStroke(new BasicStroke(plot.getAxisLineWidth()));
    }
    if (plot.getBackcolor() != null) {
        spiderWebPlot.setBackgroundPaint(plot.getBackcolor());
    }
    if (plot.getBackgroundAlpha() != null) {
        spiderWebPlot.setBackgroundAlpha(plot.getBackgroundAlpha());
    }
    if (plot.getForegroundAlpha() != null) {
        spiderWebPlot.setForegroundAlpha(plot.getForegroundAlpha());
    }
    if (plot.getHeadPercent() != null) {
        spiderWebPlot.setHeadPercent(plot.getHeadPercent());
    }
    if (plot.getInteriorGap() != null) {
        spiderWebPlot.setInteriorGap(plot.getInteriorGap());
    }
    if (plot.getLabelColor() != null) {
        spiderWebPlot.setLabelPaint(plot.getLabelColor());
    }
    if (plot.getLabelFont() != null) {
        spiderWebPlot.setLabelFont(FontUtil.getInstance(jasperReportsContext).getAwtFont(plot.getLabelFont(),
                Locale.getDefault()));
    }
    if (plot.getLabelGap() != null) {
        spiderWebPlot.setAxisLabelGap(plot.getLabelGap());
    }
    if (spiderchartBean.getMaxValue() != null) {
        spiderWebPlot.setMaxValue(spiderchartBean.getMaxValue());
    }
    if (plot.getRotation() != null) {
        spiderWebPlot.setDirection(plot.getRotation().getRotation());
    }
    if (plot.getStartAngle() != null) {
        spiderWebPlot.setStartAngle(plot.getStartAngle());
    }
    if (plot.getTableOrder() != null) {
        spiderWebPlot.setDataExtractOrder(plot.getTableOrder().getOrder());
    }
    if (plot.getWebFilled() != null) {
        spiderWebPlot.setWebFilled(plot.getWebFilled());
    }

    spiderWebPlot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    spiderWebPlot.setLabelGenerator(labelGenerator);

    Font titleFont = chartSettings.getTitleFont() != null ? FontUtil.getInstance(jasperReportsContext)
            .getAwtFont(chartSettings.getTitleFont(), Locale.getDefault()) : TextTitle.DEFAULT_FONT;

    String titleText = spiderchartBean.getTitleText();

    JFreeChart jfreechart = new JFreeChart(titleText, titleFont, spiderWebPlot, true);

    Color backcolor = chartSettings.getBackcolor() != null ? chartSettings.getBackcolor()
            : element.getBackcolor();
    if (backcolor != null) {
        jfreechart.setBackgroundPaint(backcolor);
    }

    RectangleEdge titleEdge = getEdge(chartSettings.getTitlePosition(), RectangleEdge.TOP);

    if (titleText != null) {
        TextTitle title = jfreechart.getTitle();
        title.setText(titleText);
        if (chartSettings.getTitleColor() != null) {
            title.setPaint(chartSettings.getTitleColor());
        }

        title.setFont(titleFont);
        title.setPosition(titleEdge);
        jfreechart.setTitle(title);
    }

    String subtitleText = spiderchartBean.getSubtitleText();
    if (subtitleText != null) {
        TextTitle subtitle = new TextTitle(subtitleText);
        subtitle.setText(subtitleText);
        if (chartSettings.getSubtitleColor() != null) {
            subtitle.setPaint(chartSettings.getSubtitleColor());
        }

        if (chartSettings.getSubtitleColor() != null) {
            Font subtitleFont = chartSettings.getSubtitleFont() != null
                    ? FontUtil.getInstance(jasperReportsContext).getAwtFont(chartSettings.getSubtitleFont(),
                            Locale.getDefault())
                    : TextTitle.DEFAULT_FONT;
            subtitle.setFont(subtitleFont);
        }

        subtitle.setPosition(titleEdge);

        jfreechart.addSubtitle(subtitle);
    }

    // Apply all of the legend formatting options
    LegendTitle legend = jfreechart.getLegend();

    if (legend != null) {
        legend.setVisible((chartSettings.getShowLegend() == null || chartSettings.getShowLegend()));
        if (legend.isVisible()) {
            if (chartSettings.getLegendColor() != null) {
                legend.setItemPaint(chartSettings.getLegendColor());
            }
            if (chartSettings.getLegendBackgroundColor() != null) {
                legend.setBackgroundPaint(chartSettings.getLegendBackgroundColor());
            }

            if (chartSettings.getLegendFont() != null) {
                legend.setItemFont(FontUtil.getInstance(jasperReportsContext)
                        .getAwtFont(chartSettings.getLegendFont(), Locale.getDefault()));
            }
            legend.setPosition(getEdge(chartSettings.getLegendPosition(), RectangleEdge.BOTTOM));
        }
    }

    String renderType = chartSettings.getRenderType() == null ? defaultRenderType
            : chartSettings.getRenderType();
    Rectangle2D rectangle = new Rectangle2D.Double(0, 0, element.getWidth(), element.getHeight());

    if (chartCustomizer != null) {
        chartCustomizer.customize(jfreechart, chartComponent);
    }

    return ChartUtil.getInstance(jasperReportsContext).getChartRenderableFactory(renderType)
            .getRenderable(jasperReportsContext, jfreechart, spiderchartBean.getHyperlinkProvider(), rectangle);
}

From source file:org.jfree.chart.demo.OverlaidXYPlotDemo.java

/**
 * Creates an overlaid chart.//from  w ww.ja  v  a2  s  . co m
 *
 * @return The chart.
 */
private JFreeChart createOverlaidChart() {

    // 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 DateAxis domainAxis = new DateAxis("Date");
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    final ValueAxis rangeAxis = new NumberAxis("Value");
    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);

    // add a second dataset and renderer...
    final XYDataset data2 = createDataset2();
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    plot.setDataset(1, data2);
    plot.setRenderer(1, renderer2);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    // return a new chart containing the overlaid plot...
    return new JFreeChart("Overlaid Plot Example", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

}

From source file:org.pentaho.plugin.jfreereport.reportcharts.AreaChartExpression.java

/**
 * Creates a stacked area chart with default settings.  The chart object returned by this method uses a {@link
 * CategoryPlot} instance as the plot, with a {@link org.jfree.chart.axis.CategoryAxis} for the domain axis, a {@link
 * org.jfree.chart.axis.NumberAxis} as the range axis, and a {@link org.jfree.chart.renderer.category
 * .StackedAreaRenderer}/*from  w ww  .j  a v a2 s .c om*/
 * as the renderer.
 *
 * @param title             the chart title (<code>null</code> permitted).
 * @param categoryAxisLabel the label for the category axis (<code>null</code> permitted).
 * @param valueAxisLabel    the label for the value axis (<code>null</code> permitted).
 * @param dataset           the dataset for the chart (<code>null</code> permitted).
 * @param orientation       the plot orientation (horizontal or vertical) (<code>null</code> not permitted).
 * @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 area chart.
 */
private JFreeChart createStackedAreaChart(final String title, final String categoryAxisLabel,
        final String valueAxisLabel, final CategoryDataset dataset, final PlotOrientation orientation,
        final boolean legend, final boolean tooltips, final boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    final CategoryAxis categoryAxis = new FormattedCategoryAxis(categoryAxisLabel,
            getCategoricalAxisMessageFormat(), getRuntime().getResourceBundleFactory().getLocale());
    categoryAxis.setCategoryMargin(0.0);
    final ValueAxis valueAxis = new NumberAxis(valueAxisLabel);

    final StackedAreaRenderer renderer = new StackedAreaRenderer();
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
    }

    final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
}

From source file:org.drools.planner.benchmark.core.statistic.memoryuse.MemoryUseProblemStatistic.java

protected void writeGraphStatistic() {
    XYSeriesCollection seriesCollection = new XYSeriesCollection();
    for (SingleBenchmark singleBenchmark : problemBenchmark.getSingleBenchmarkList()) {
        MemoryUseSingleStatistic singleStatistic = (MemoryUseSingleStatistic) singleBenchmark
                .getSingleStatistic(problemStatisticType);
        XYSeries usedSeries = new XYSeries(singleBenchmark.getSolverBenchmark().getName() + " used");
        XYSeries maxSeries = new XYSeries(singleBenchmark.getSolverBenchmark().getName() + " max");
        for (MemoryUseSingleStatisticPoint point : singleStatistic.getPointList()) {
            long timeMillisSpend = point.getTimeMillisSpend();
            MemoryUseMeasurement memoryUseMeasurement = point.getMemoryUseMeasurement();
            usedSeries.add(timeMillisSpend, memoryUseMeasurement.getUsedMemory());
            maxSeries.add(timeMillisSpend, memoryUseMeasurement.getMaxMemory());
        }//from   w w  w . jav a 2 s .  c om
        seriesCollection.addSeries(usedSeries);
        seriesCollection.addSeries(maxSeries);
    }
    NumberAxis xAxis = new NumberAxis("Time spend");
    xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat());
    NumberAxis yAxis = new NumberAxis("Memory");
    yAxis.setAutoRangeIncludesZero(false);
    XYItemRenderer renderer = new XYAreaRenderer2();
    XYPlot plot = new XYPlot(seriesCollection, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart(problemBenchmark.getName() + " memory use statistic",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    graphStatisticFile = new File(problemBenchmark.getProblemReportDirectory(),
            problemBenchmark.getName() + "MemoryUseStatistic.png");
    OutputStream out = null;
    try {
        out = new FileOutputStream(graphStatisticFile);
        ImageIO.write(chartImage, "png", out);
    } catch (IOException e) {
        throw new IllegalArgumentException("Problem writing graphStatisticFile: " + graphStatisticFile, e);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:org.optaplanner.benchmark.impl.statistic.stepscore.StepScoreProblemStatistic.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()) {
            StepScoreSingleStatistic singleStatistic = (StepScoreSingleStatistic) singleBenchmarkResult
                    .getSingleStatistic(problemStatisticType);
            for (StepScoreStatisticPoint 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  w w  .  j av a  2s  .c  o  m
                    seriesList.get(i).add(timeMillisSpent, levelValues[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() + " step score level " + scoreLevelIndex + " statistic",
                JFreeChart.DEFAULT_TITLE_FONT, plotList.get(scoreLevelIndex), true);
        graphFileList.add(writeChartToImageFile(chart,
                problemBenchmarkResult.getName() + "StepScoreStatisticLevel" + scoreLevelIndex));
    }
}

From source file:de.bund.bfr.knime.nls.chart.ChartCreator.java

public JFreeChart createChart() throws ParseException {
    if (varX == null || varY == null) {
        return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, new XYPlot(), showLegend);
    }//www. j ava 2s  .c o  m

    List<String> idsToPaint;

    if (selectAll) {
        idsToPaint = new ArrayList<>(plotables.keySet());
    } else {
        idsToPaint = selectedIds;
    }

    NumberAxis xAxis = new NumberAxis(transformX.getName(varX));
    NumberAxis yAxis = new NumberAxis(transformY.getName(varY));
    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.isDataType()) {
            double[][] points = plotable.getDataPoints(varX, varY, transformX, transformY);

            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.isParamType()) {
            double minArg = transformX.to(MathUtils.nullToNan(plotable.getMinValues().get(varX)));
            double maxArg = transformX.to(MathUtils.nullToNan(plotable.getMaxValues().get(varX)));

            if (Double.isFinite(minArg)) {
                usedMinX = Math.min(usedMinX, minArg);
            }

            if (Double.isFinite(maxArg)) {
                usedMaxX = Math.max(usedMaxX, maxArg);
            }
        }
    }

    if (!Double.isFinite(usedMinX)) {
        usedMinX = 0.0;
    }

    if (!Double.isFinite(usedMaxX)) {
        usedMaxX = 100.0;
    }

    xAxis.setAutoRangeIncludesZero(false);
    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);
        plotable.setInterpolator(interpolator);

        switch (plotable.getType()) {
        case DATA:
            plotData(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index));
            break;
        case FUNCTION:
            plotFunction(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX,
                    usedMaxX);
            break;
        case DATA_FUNCTION:
            plotDataFunction(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX,
                    usedMaxX);
            break;
        case DIFF:
            plotDiff(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX,
                    usedMaxX);
            break;
        case DATA_DIFF:
            plotDataDiff(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX,
                    usedMaxX);
            break;
        default:
            throw new RuntimeException("Unknown type of plotable: " + plotable.getType());
        }

        index++;
    }

    if (minToZero && !useManualRange) {
        Range xRange = xAxis.getRange();
        Range yRange = yAxis.getRange();

        if (xRange.getUpperBound() <= 0.0 || yRange.getUpperBound() <= 0.0) {
            return null;
        }

        xAxis.setRange(new Range(0.0, xRange.getUpperBound()));
        yAxis.setRange(new Range(0.0, yRange.getUpperBound()));
    }

    return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, showLegend);
}