Example usage for org.jfree.chart.plot XYPlot XYPlot

List of usage examples for org.jfree.chart.plot XYPlot XYPlot

Introduction

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

Prototype

public XYPlot(XYDataset dataset, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer) 

Source Link

Document

Creates a new plot with the specified dataset, axes and renderer.

Usage

From source file:loci.slim.ui.ExcitationGraph.java

/**
 * Creates the chart/* w  w  w  .j ava  2s . c  o  m*/
 *
 * @param bins number of bins
 * @param timeInc time increment per bin
 * @param data fitted data
 * @return the chart
 */
JFreeChart createChart(final int bins, final double timeInc, final double[] values) {

    // create chart data
    createDataset(bins, timeInc, values);

    // make a horizontal axis
    final NumberAxis timeAxis = new NumberAxis(TIME_AXIS_LABEL);
    timeAxis.setLabel(UNITS_LABEL);
    timeAxis.setRange(0.0, (bins - 1) * timeInc);

    // make a vertical axis
    NumberAxis photonAxis;
    if (_logarithmic) {
        photonAxis = new LogarithmicAxis(PHOTON_AXIS_LABEL);
    } else {
        photonAxis = new NumberAxis(PHOTON_AXIS_LABEL);
    }

    // make an excitation plot
    final XYSplineRenderer excitationRenderer = new XYSplineRenderer();
    excitationRenderer.setSeriesShapesVisible(0, false);
    excitationRenderer.setSeriesPaint(0, EXCITATION_COLOR);

    _excitationPlot = new XYPlot(_excitationDataset, timeAxis, photonAxis, excitationRenderer);
    _excitationPlot.setDomainCrosshairVisible(true);
    _excitationPlot.setRangeCrosshairVisible(true);

    // now make the top level JFreeChart
    final JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, _excitationPlot, true);
    chart.removeLegend();

    return chart;
}

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

/**
 * Creates and returns a default instance of an XY bar chart.
 * <p/>/*from  w ww  .j a v  a2s . c  o m*/
 * The chart object returned by this method uses an {@link XYPlot} instance as the plot, with a {@link
 * org.jfree.chart.axis.DateAxis} for the domain axis, a {@link org.jfree.chart.axis.NumberAxis} as the range axis,
 * and a {@link XYBarRenderer} as the renderer.
 *
 * @param title       the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param dateAxis    make the domain axis display dates?
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset     the dataset for the chart (<code>null</code> permitted).
 * @param orientation the 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 An XY bar chart.
 */
public static JFreeChart createXYBarChart(final String title, final String xAxisLabel, final boolean dateAxis,
        final String yAxisLabel, final XYDataset dataset, final PlotOrientation orientation,
        final boolean legend, final boolean tooltips, final boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    ValueAxis domainAxis = null;
    if (dateAxis) {
        domainAxis = new DateAxis(xAxisLabel);
    } else {
        final NumberAxis axis = new NumberAxis(xAxisLabel);
        axis.setAutoRangeIncludesZero(false);
        domainAxis = axis;
    }
    final ValueAxis valueAxis = new NumberAxis(yAxisLabel);

    final XYBarRenderer renderer = new XYBarRenderer();
    renderer.setUseYInterval(true);
    if (tooltips) {
        final XYToolTipGenerator tt;
        if (dateAxis) {
            tt = StandardXYToolTipGenerator.getTimeSeriesInstance();
        } else {
            tt = new StandardXYToolTipGenerator();
        }
        renderer.setBaseToolTipGenerator(tt);
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    final XYPlot plot = new XYPlot(dataset, domainAxis, valueAxis, renderer);
    plot.setOrientation(orientation);

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

From source file:weka.classifiers.timeseries.eval.graph.JFreeChartDriver.java

protected JFreeChart getPredictedTargetsChart(TSForecaster forecaster, ErrorModule preds,
        List<String> targetNames, int stepNumber, int instanceNumOffset, Instances data) {

    if (forecaster instanceof TSLagUser && data != null) {
        TSLagMaker lagMaker = ((TSLagUser) forecaster).getTSLagMaker();
        if (lagMaker.getAdjustForTrends() && !lagMaker.isUsingAnArtificialTimeIndex()) {

            // fill in any missing time stamps only
            data = new Instances(data);
            data = weka.classifiers.timeseries.core.Utils.replaceMissing(data, null,
                    lagMaker.getTimeStampField(), true, lagMaker.getPeriodicity(), lagMaker.getSkipEntries());
        }/*  w  w w.  ja  va2 s.  c  o m*/
    }

    // set up a collection of predicted and actual series
    XYIntervalSeriesCollection xyDataset = new XYIntervalSeriesCollection();
    for (String target : targetNames) {
        XYIntervalSeries targetSeries = new XYIntervalSeries(target + "-actual", false, false);
        xyDataset.addSeries(targetSeries);
        targetSeries = new XYIntervalSeries(target + "-predicted", false, false);
        xyDataset.addSeries(targetSeries);

    }

    ValueAxis timeAxis = null;
    NumberAxis valueAxis = new NumberAxis("");
    valueAxis.setAutoRangeIncludesZero(false);
    int timeIndex = -1;
    boolean timeAxisIsDate = false;
    if (forecaster instanceof TSLagUser && data != null) {
        TSLagMaker lagMaker = ((TSLagUser) forecaster).getTSLagMaker();
        if (!lagMaker.isUsingAnArtificialTimeIndex() && lagMaker.getAdjustForTrends()) {
            String timeName = lagMaker.getTimeStampField();
            if (data.attribute(timeName).isDate()) {
                timeAxis = new DateAxis("");
                timeAxisIsDate = true;
                timeIndex = data.attribute(timeName).index();
            }
        }
    }

    if (timeAxis == null) {
        timeAxis = new NumberAxis("");
        ((NumberAxis) timeAxis).setAutoRangeIncludesZero(false);
    }

    // now populate the series
    boolean hasConfidenceIntervals = false;
    for (int i = 0; i < targetNames.size(); i++) {
        String targetName = targetNames.get(i);
        List<NumericPrediction> predsForI = preds.getPredictionsForTarget(targetName);
        int predIndex = xyDataset.indexOf(targetName + "-predicted");
        int actualIndex = xyDataset.indexOf(targetName + "-actual");
        XYIntervalSeries predSeries = xyDataset.getSeries(predIndex);
        XYIntervalSeries actualSeries = xyDataset.getSeries(actualIndex);

        for (int j = 0; j < predsForI.size(); j++) {
            double x = Utils.missingValue();
            if (timeAxisIsDate) {
                if (instanceNumOffset + j + stepNumber - 1 < data.numInstances()) {
                    x = data.instance(instanceNumOffset + j + stepNumber - 1).value(timeIndex);
                }
            } else {
                x = instanceNumOffset + j + stepNumber;
            }

            double yPredicted = predsForI.get(j).predicted();
            double yHigh = yPredicted;
            double yLow = yPredicted;
            double[][] conf = predsForI.get(j).predictionIntervals();
            if (conf.length > 0) {
                yLow = conf[0][0];
                yHigh = conf[0][1];
                hasConfidenceIntervals = true;
            }
            if (!Utils.isMissingValue(x) && !Utils.isMissingValue(yPredicted)) {
                if (predSeries != null) {
                    predSeries.add(x, x, x, yPredicted, yLow, yHigh);
                }
                // System.err.println("* " + yPredicted + " " + x);
            }

            double yActual = predsForI.get(j).actual();
            if (!Utils.isMissingValue(x) && !Utils.isMissingValue(yActual)) {
                if (actualSeries != null) {
                    actualSeries.add(x, x, x, yActual, yActual, yActual);
                }
            }
        }
    }

    // set up the chart
    String title = "" + stepNumber + " step-ahead predictions for: ";
    for (String s : targetNames) {
        title += s + ",";
    }
    title = title.substring(0, title.lastIndexOf(","));

    /*
     * String algoSpec = forecaster.getAlgorithmName(); title += " (" + algoSpec
     * + ")";
     */

    if (forecaster instanceof WekaForecaster && hasConfidenceIntervals) {
        double confPerc = ((WekaForecaster) forecaster).getConfidenceLevel() * 100.0;
        title += " [" + Utils.doubleToString(confPerc, 0) + "% conf. intervals]";
    }

    XYErrorRenderer renderer = new XYErrorRenderer();
    renderer.setBaseLinesVisible(true);
    renderer.setDrawXError(false);
    renderer.setDrawYError(true);
    // renderer.setShapesFilled(true);
    XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    chart.setBackgroundPaint(java.awt.Color.white);
    TextTitle chartTitle = chart.getTitle();
    String fontName = chartTitle.getFont().getFontName();
    java.awt.Font newFont = new java.awt.Font(fontName, java.awt.Font.PLAIN, 12);
    chartTitle.setFont(newFont);

    return chart;
}

From source file:loci.slim2.process.interactive.ui.DefaultExcitationGraph.java

/**
 * Creates the chart//from ww  w  . jav  a  2  s. c  o m
 *
 * @param bins number of bins
 * @param timeInc time increment per bin
 * @param data fitted data
 * @return the chart
 */
JFreeChart createChart(final int bins, final double timeInc, final double[] values) {

    // create chart data
    createDataset(bins, timeInc, values);

    // make a horizontal axis
    final NumberAxis timeAxis = new NumberAxis(TIME_AXIS_LABEL);
    timeAxis.setLabel(UNITS_LABEL);
    timeAxis.setRange(0.0, (bins - 1) * timeInc);

    // make a vertical axis
    NumberAxis photonAxis;
    if (logarithmic) {
        photonAxis = new LogarithmicAxis(PHOTON_AXIS_LABEL);
    } else {
        photonAxis = new NumberAxis(PHOTON_AXIS_LABEL);
    }

    // make an excitation plot
    final XYSplineRenderer excitationRenderer = new XYSplineRenderer();
    excitationRenderer.setSeriesShapesVisible(0, false);
    excitationRenderer.setSeriesPaint(0, EXCITATION_COLOR);

    excitationPlot = new XYPlot(excitationDataset, timeAxis, photonAxis, excitationRenderer);
    excitationPlot.setDomainCrosshairVisible(true);
    excitationPlot.setRangeCrosshairVisible(true);

    // now make the top level JFreeChart
    final JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, excitationPlot, true);
    chart.removeLegend();

    return chart;
}

From source file:pisco.batch.visu.BatchingChartFactory.java

public static XYPlot createWFlowtimePlot(Batch[] batches) {
    ValueAxis timeAxis = new DateAxis("");
    NumberAxis valueAxis = new NumberAxis("Cum. WFlow");
    valueAxis.setAutoRangeIncludesZero(false);
    XYPlot plot = new XYPlot(createWFlowtimeDataset(batches), timeAxis, valueAxis, null);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true);
    renderer.setBaseToolTipGenerator(new WFlowLabelToolTipGenerator(batches));
    plot.setRenderer(renderer);/*from   ww  w .  j  av a2s.  com*/
    return plot;
}

From source file:org.drools.planner.benchmark.statistic.bestscore.BestScoreStatistic.java

private CharSequence writeGraphStatistic(File solverStatisticFilesDirectory, String baseName) {
    NumberAxis xAxis = new NumberAxis("Time millis spend");
    xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat());
    NumberAxis yAxis = new NumberAxis("Score");
    yAxis.setAutoRangeIncludesZero(false);
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    int seriesIndex = 0;
    for (Map.Entry<String, BestScoreStatisticListener> listenerEntry : bestScoreStatisticListenerMap
            .entrySet()) {/*  w ww .j a v a2  s . com*/
        String configName = listenerEntry.getKey();
        XYSeries series = new XYSeries(configName);
        List<BestScoreStatisticPoint> statisticPointList = listenerEntry.getValue().getStatisticPointList();
        for (BestScoreStatisticPoint statisticPoint : statisticPointList) {
            long timeMillisSpend = statisticPoint.getTimeMillisSpend();
            Score score = statisticPoint.getScore();
            Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score);
            if (scoreGraphValue != null) {
                series.add(timeMillisSpend, scoreGraphValue);
            }
        }
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(series);
        plot.setDataset(seriesIndex, seriesCollection);
        XYItemRenderer renderer;
        // No direct lines between 2 points
        renderer = new XYStepRenderer();
        if (statisticPointList.size() <= 1) {
            // Workaround for https://sourceforge.net/tracker/?func=detail&aid=3387330&group_id=15494&atid=115494
            renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES);
        }
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;
    }
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart(baseName + " best score statistic", JFreeChart.DEFAULT_TITLE_FONT, plot,
            true);
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    File graphStatisticFile = new File(solverStatisticFilesDirectory, baseName + "BestScoreStatistic.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);
    }
    return "  <img src=\"" + graphStatisticFile.getName() + "\"/>\n";
}

From source file:com.att.aro.ui.view.diagnostictab.CreateBarPlot.java

public XYPlot drawStepChartPlot() {
    XYStepRenderer renderer = new XYStepRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer.setSeriesStroke(1, new BasicStroke(2.0f));
    renderer.setDefaultEntityRadius(6);//from  w ww.  j  a  v  a 2 s  .  c om
    XYPlot plot = new XYPlot(null, null, new NumberAxis(), renderer);
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    return plot;
}

From source file:jgnash.ui.report.compiled.RunningAccountBalanceChart.java

private JFreeChart createVerticalXYBarChart(Account a) {

    DateFormat df = new SimpleDateFormat("MM/yy");

    TimeSeriesCollection data = createTimeSeriesCollection(a);

    DateAxis dateAxis = new DateAxis(rb.getString("Column.Date"));
    dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1, df));
    dateAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);

    LocalDate start = DateUtils.getFirstDayOfTheMonth(startDateField.getLocalDate());
    LocalDate end = DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate());

    dateAxis.setRange(DateUtils.asDate(start), DateUtils.asDate(end));

    NumberAxis valueAxis = new NumberAxis(rb.getString("Column.Balance"));
    StandardXYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator("{1}, {2}", df,
            NumberFormat.getNumberInstance());

    XYBarRenderer renderer = new XYBarRenderer(0.2);
    renderer.setBaseToolTipGenerator(tooltipGenerator);

    XYPlot plot = new XYPlot(data, dateAxis, valueAxis, renderer);

    String title = rb.getString("Title.EndMonthBalance") + " - " + a.getPathName();

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    chart.setBackgroundPaint(null);/* w w  w . j a v  a  2 s  .co  m*/

    return chart;
}

From source file:org.optaplanner.examples.cheaptime.swingui.CheapTimePanel.java

private XYPlot createPeriodCostPlot(TangoColorFactory tangoColorFactory, CheapTimeSolution solution) {
    XYSeries series = new XYSeries("Power price");
    for (PeriodPowerPrice periodPowerPrice : solution.getPeriodPowerPriceList()) {
        series.add((double) periodPowerPrice.getPowerPriceMicros() / 1000000.0, periodPowerPrice.getPeriod());
    }/*from w w  w .ja  v a  2 s .  c  o  m*/
    XYSeriesCollection seriesCollection = new XYSeriesCollection();
    seriesCollection.addSeries(series);
    XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES);
    renderer.setSeriesPaint(0, TangoColorFactory.ORANGE_1);
    renderer.setSeriesShape(0, ShapeUtilities.createDiamond(2.0F));
    NumberAxis domainAxis = new NumberAxis("Power price");
    return new XYPlot(seriesCollection, domainAxis, null, renderer);
}

From source file:projects.hip.exec.HrDiagram.java

/**
 * Plot the distribution of distance of all objects.
 * @param d_hist/*from   ww  w.j  a  v  a2s  .  c  om*/
 *    The array containing the distance distribution histogram.
 * @return
 *    A {@link JFreeChart} containing the plot.
 */
private static JFreeChart getDistanceChart(double[] d_hist) {

    XYSeries series = new XYSeries("Distance distribution");

    for (int i = 0; i < d_hist.length; i++) {
        // Centre of this distance bin
        double d = d_min + i * d_step + d_step / 2.0;
        series.add(d, d_hist[i]);
    }
    XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(series);

    // Set up the renderer
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, false);

    // Configure axes
    NumberAxis xAxis = new NumberAxis("Distance [pc]");
    xAxis.setRange(d_min, d_max);

    NumberAxis yAxis = new NumberAxis("Number of objects");
    yAxis.setAutoRangeIncludesZero(true);

    // Configure plot
    XYPlot xyplot = new XYPlot(data, xAxis, yAxis, renderer);
    xyplot.setBackgroundPaint(Color.white);

    JFreeChart dChart = new JFreeChart("Distance distribution of Hipparcos stars", xyplot);
    dChart.removeLegend();
    dChart.setBackgroundPaint(Color.white);

    return dChart;
}