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

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

Introduction

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

Prototype

public void setDataset(int index, XYDataset dataset) 

Source Link

Document

Sets a dataset for the plot and sends a change event to all registered listeners.

Usage

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

protected void writeGraphStatistic() {
    NumberAxis xAxis = new NumberAxis("Time 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 (SingleBenchmark singleBenchmark : problemBenchmark.getSingleBenchmarkList()) {
        BestScoreSingleStatistic singleStatistic = (BestScoreSingleStatistic) singleBenchmark
                .getSingleStatistic(problemStatisticType);
        XYSeries series = new XYSeries(singleBenchmark.getSolverBenchmark().getName());
        for (BestScoreSingleStatisticPoint point : singleStatistic.getPointList()) {
            long timeMillisSpend = point.getTimeMillisSpend();
            Score score = point.getScore();
            Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score);
            if (scoreGraphValue != null) {
                series.add(timeMillisSpend, scoreGraphValue);
            }//w  w w  .jav  a  2  s  .  c om
        }
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(series);
        plot.setDataset(seriesIndex, seriesCollection);
        XYItemRenderer renderer;
        // No direct lines between 2 points
        renderer = new XYStepRenderer();
        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);
        }
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;
    }
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart(problemBenchmark.getName() + " best score statistic",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    graphStatisticFile = new File(problemBenchmark.getProblemReportDirectory(),
            problemBenchmark.getName() + "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);
    }
}

From source file:org.optaplanner.benchmark.impl.statistic.calculatecount.CalculateCountProblemStatistic.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("Calculate count per second");
    yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    yAxis.setAutoRangeIncludesZero(false);
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    plot.setOrientation(PlotOrientation.VERTICAL);
    int seriesIndex = 0;
    for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) {
        XYSeries series = new XYSeries(
                singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix());
        XYItemRenderer renderer = new XYLineAndShapeRenderer();
        if (singleBenchmarkResult.isSuccess()) {
            CalculateCountSingleStatistic singleStatistic = (CalculateCountSingleStatistic) singleBenchmarkResult
                    .getSingleStatistic(problemStatisticType);
            for (CalculateCountStatisticPoint point : singleStatistic.getPointList()) {
                long timeMillisSpent = point.getTimeMillisSpent();
                long calculateCountPerSecond = point.getCalculateCountPerSecond();
                series.add(timeMillisSpent, calculateCountPerSecond);
            }//from   ww  w .j a  v a 2  s .c  om
        }
        plot.setDataset(seriesIndex, new XYSeriesCollection(series));

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

From source file:ec.util.chart.swing.JTimeSeriesChart.java

private void onDatasetChange(final XYPlot plot) {
    int plotIndex = roSubPlots.indexOf(plot);
    int rendererIndex = 0;
    for (RendererType o : supportedRendererTypes) {
        int[] map = seriesMapFactory.getSeriesMap(o, plotIndex);
        plot.setDataset(rendererIndex++, new FilteredXYDataset(dataset, map));
    }//from w  ww .  j  av a2  s .c o  m
}

From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreeTimeChartData.java

private TimeChartDataSet addTimeSeries(TimeChartDataSet dataset) throws InvalidArgument {
    if (dataset == null) {
        dataset = makeDataSet(1);/*from  w ww  .  j av  a 2s .  c om*/
    }

    if (chart == null) {
        chart = ChartFactory.createTimeSeriesChart(title, "Time", quantity, dataset, true, false, false);
        XYPlot xyPlot = (XYPlot) chart.getPlot();

        DateAxis axis = (DateAxis) xyPlot.getDomainAxis();
        //axis.setRange(period.getStart(), period.getEnd());
        //axis.setLowerMargin(0.0);
        //axis.setUpperMargin(0.0);

        if (period instanceof CalendarFieldSplitPeriod) {
            TickUnits u = getUnits((CalendarFieldSplitPeriod) period);
            if (u != null) {
                axis.setStandardTickUnits(u);
            }
        }
        axis.setMinimumDate(period.getStart());
        axis.setMaximumDate(period.getEnd());
        LegendTitle leg = chart.getLegend();
        leg.setSortOrder(SortOrder.DESCENDING);
        leg.setPosition(RectangleEdge.RIGHT);
    } else {
        XYPlot xyPlot = (XYPlot) chart.getPlot();
        xyPlot.setDataset(ndatasets, dataset);
    }
    dataset.setDatasetId(ndatasets);
    ndatasets++;
    plots.add(dataset);
    return dataset;
}

From source file:org.esa.beam.visat.toolviews.stat.ScatterPlotPanel.java

private void createUI() {

    final XYPlot plot = getPlot();
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    plot.setNoDataMessage(NO_DATA_MESSAGE);
    plot.setDataset(CONFIDENCE_DSINDEX, acceptableDeviationDataset);
    plot.setDataset(REGRESSION_DSINDEX, regressionDataset);
    plot.setDataset(SCATTERPOINTS_DSINDEX, scatterpointsDataset);

    plot.addAnnotation(r2Annotation);

    final DeviationRenderer identityRenderer = new DeviationRenderer(true, false);
    identityRenderer.setSeriesPaint(0, StatisticChartStyling.SAMPLE_DATA_PAINT);
    identityRenderer.setSeriesFillPaint(0, StatisticChartStyling.SAMPLE_DATA_FILL_PAINT);
    plot.setRenderer(CONFIDENCE_DSINDEX, identityRenderer);

    final DeviationRenderer regressionRenderer = new DeviationRenderer(true, false);
    regressionRenderer.setSeriesPaint(0, StatisticChartStyling.REGRESSION_DATA_PAINT);
    regressionRenderer.setSeriesFillPaint(0, StatisticChartStyling.REGRESSION_DATA_FILL_PAINT);
    plot.setRenderer(REGRESSION_DSINDEX, regressionRenderer);

    final XYErrorRenderer scatterPointsRenderer = new XYErrorRenderer();
    scatterPointsRenderer.setDrawXError(true);
    scatterPointsRenderer.setErrorStroke(new BasicStroke(1));
    scatterPointsRenderer.setErrorPaint(StatisticChartStyling.CORRELATIVE_POINT_OUTLINE_PAINT);
    scatterPointsRenderer.setSeriesShape(0, StatisticChartStyling.CORRELATIVE_POINT_SHAPE);
    scatterPointsRenderer.setSeriesOutlinePaint(0, StatisticChartStyling.CORRELATIVE_POINT_OUTLINE_PAINT);
    scatterPointsRenderer.setSeriesFillPaint(0, StatisticChartStyling.CORRELATIVE_POINT_FILL_PAINT);
    scatterPointsRenderer.setSeriesLinesVisible(0, false);
    scatterPointsRenderer.setSeriesShapesVisible(0, true);
    scatterPointsRenderer.setSeriesOutlineStroke(0, new BasicStroke(1.0f));
    scatterPointsRenderer.setSeriesToolTipGenerator(0, new XYToolTipGenerator() {
        @Override//from  w  ww. j a va  2  s .  co  m
        public String generateToolTip(XYDataset dataset, int series, int item) {
            final XYIntervalSeriesCollection collection = (XYIntervalSeriesCollection) dataset;
            final Comparable key = collection.getSeriesKey(series);
            final double xValue = collection.getXValue(series, item);
            final double endYValue = collection.getEndYValue(series, item);
            final double yValue = collection.getYValue(series, item);
            return String.format("%s: mean = %6.2f, sigma = %6.2f | %s: value = %6.2f", getRasterName(), yValue,
                    endYValue - yValue, key, xValue);
        }
    });
    plot.setRenderer(SCATTERPOINTS_DSINDEX, scatterPointsRenderer);

    final boolean autoRangeIncludesZero = false;
    final boolean xLog = scatterPlotModel.xAxisLogScaled;
    final boolean yLog = scatterPlotModel.yAxisLogScaled;
    plot.setDomainAxis(
            StatisticChartStyling.updateScalingOfAxis(xLog, plot.getDomainAxis(), autoRangeIncludesZero));
    plot.setRangeAxis(
            StatisticChartStyling.updateScalingOfAxis(yLog, plot.getRangeAxis(), autoRangeIncludesZero));

    createUI(createChartPanel(chart), createInputParameterPanel(), bindingContext);

    plot.getDomainAxis().addChangeListener(domainAxisChangeListener);
    scatterPlotDisplay.setMouseWheelEnabled(true);
    scatterPlotDisplay.setMouseZoomable(true);
}

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

/**
 * Creates the demo chart.//from  ww w.jav a  2s  .  c  o m
 * 
 * @return The chart.
 */
private JFreeChart createChart() {

    // create some sample data

    final XYSeries series1 = new XYSeries("Something");
    series1.add(0.0, 30.0);
    series1.add(1.0, 10.0);
    series1.add(2.0, 40.0);
    series1.add(3.0, 30.0);
    series1.add(4.0, 50.0);
    series1.add(5.0, 50.0);
    series1.add(6.0, 70.0);
    series1.add(7.0, 70.0);
    series1.add(8.0, 80.0);

    final XYSeriesCollection dataset1 = new XYSeriesCollection();
    dataset1.addSeries(series1);

    final XYSeries series2 = new XYSeries("Something else");
    series2.add(0.0, 5.0);
    series2.add(1.0, 4.0);
    series2.add(2.0, 1.0);
    series2.add(3.0, 5.0);
    series2.add(4.0, 0.0);

    final XYSeriesCollection dataset2 = new XYSeriesCollection();
    dataset2.addSeries(series2);

    // create the chart

    final JFreeChart result = ChartFactory.createXYLineChart("Tick Label Demo", "Domain Axis 1", "Range Axis 1",
            dataset1, PlotOrientation.VERTICAL, false, true, false);

    result.setBackgroundPaint(Color.white);
    final XYPlot plot = result.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //      plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));

    final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setPaint(Color.black);

    // DOMAIN AXIS 2
    final NumberAxis xAxis2 = new NumberAxis("Domain Axis 2");
    xAxis2.setAutoRangeIncludesZero(false);
    plot.setDomainAxis(1, xAxis2);

    // RANGE AXIS 2
    final DateAxis yAxis1 = new DateAxis("Range Axis 1");
    plot.setRangeAxis(yAxis1);

    final DateAxis yAxis2 = new DateAxis("Range Axis 2");
    plot.setRangeAxis(1, yAxis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

    plot.setDataset(1, dataset2);
    plot.mapDatasetToDomainAxis(1, 1);
    plot.mapDatasetToRangeAxis(1, 1);

    return result;
}

From source file:net.vanosten.dings.swing.SummaryView.java

public void displayTimeSeriesChart(final TimeSeriesCollection averageScore, final int maxScoreRange,
        final TimeSeriesCollection numberOfEntries, final int maxTotalRange) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time Series", "Date", "Average Score",
            averageScore, true, true, false);

    chart.setBackgroundPaint(Color.white);
    final XYPlot plot = chart.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYItemRenderer renderer1 = plot.getRenderer();
    renderer1.setPaint(Color.blue);

    //axis 1/*from   w w  w  .  jav  a  2 s  .  co  m*/
    final NumberAxis axis1 = new NumberAxis("Average Score");
    axis1.setLabelPaint(Color.blue);
    axis1.setTickLabelPaint(Color.blue);
    axis1.setRange(0.0d, maxScoreRange + 1);
    plot.setRangeAxis(0, axis1);

    //axis 2
    final NumberAxis axis2 = new NumberAxis("Number of Entries");
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    axis2.setRange(0.0d, 10 * (((int) (maxTotalRange / 10)) + 1));
    plot.setRangeAxis(1, axis2);

    plot.setDataset(1, numberOfEntries);
    plot.mapDatasetToRangeAxis(1, 1);
    final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setPaint(Color.red);
    plot.setRenderer(1, renderer2);

    placeChart(chart);
}

From source file:ca.myewb.frame.servlet.GraphServlet.java

private JFreeChart getDailyIntegratedStats(Session s) throws CloneNotSupportedException {
    JFreeChart chart;/*from w  ww  . j  av  a2s . com*/
    List<DailyStatsModel> stats = (new SafeHibList<DailyStatsModel>(
            s.createQuery("select ds from DailyStatsModel as ds where day<? and day>=? order by day desc")
                    .setDate(0, new Date()).setDate(1, GraphServlet.getStartDate()))).list();
    TimeSeriesCollection theData = new TimeSeriesCollection();
    TimeSeriesCollection theData2 = new TimeSeriesCollection();

    TimeSeries users = new TimeSeries("Total Users", Day.class);
    theData.addSeries(users);

    TimeSeries regulars = new TimeSeries("Regular Members", Day.class);
    theData2.addSeries(regulars);

    int numUsers = Helpers.getGroup("Org").getNumMembers();
    int numReg = Helpers.getGroup("Regular").getNumMembers();

    for (DailyStatsModel ds : stats) {
        Day theDay = new Day(ds.getDay());
        users.add(theDay, numUsers);
        regulars.add(theDay, numReg);
        numUsers -= (ds.getMailinglistsignups() + ds.getSignups() - ds.getDeletions());
        numReg -= (ds.getRegupgrades() - ds.getRegdowngrades());
    }

    chart = ChartFactory.createTimeSeriesChart("Membership", "Day", "Users", theData, true, true, true);

    XYPlot plot = (XYPlot) chart.getPlot();

    NumberAxis axis2 = new NumberAxis("Regular Members");
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    plot.setDataset(1, MovingAverage.createMovingAverage(theData2, "", 14, 0));
    plot.mapDatasetToRangeAxis(1, 1);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(0);
    renderer.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer = (XYLineAndShapeRenderer) renderer.clone();
    renderer.setSeriesStroke(0, new BasicStroke(2.0f));
    plot.setRenderer(1, renderer);
    return chart;
}

From source file:ca.myewb.frame.servlet.GraphServlet.java

private JFreeChart getLastLogin(Session s) throws CloneNotSupportedException {

    Integer numCurrentLogins = ((Long) s
            .createQuery("select count(*) from UserModel "
                    + "where currentLogin is not null and currentLogin >= :date")
            .setDate("date", getStartDate()).uniqueResult()).intValue();

    List currentStats = s/*from w w w  . ja v  a 2s .  c o m*/
            .createSQLQuery("SELECT DATE(currentLogin) as date, count( * ) as lastLogins "
                    + "FROM users where currentLogin is not null  and currentLogin >= :date "
                    + "GROUP BY DATE( currentLogin )")
            .addScalar("date", Hibernate.DATE).addScalar("lastLogins", Hibernate.INTEGER)
            .setDate("date", getStartDate()).list();

    TimeSeriesCollection theData = new TimeSeriesCollection();
    TimeSeriesCollection theData2 = new TimeSeriesCollection();

    TimeSeries current = new TimeSeries("Num Latest Sign-ins", Day.class);
    theData.addSeries(current);
    TimeSeries current2 = new TimeSeries("Signed-in Users Since", Day.class);
    theData2.addSeries(current2);

    for (Object ds : currentStats) {
        Date date = (Date) ((Object[]) ds)[0];
        Day day = new Day(date);
        Integer integer = (Integer) ((Object[]) ds)[1];
        current.add(day, integer);
        numCurrentLogins -= integer.intValue();
        current2.add(day, numCurrentLogins);

    }

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Sign-in Recency", "Day", "Sign-ins", theData, true,
            true, true);

    XYPlot plot = (XYPlot) chart.getPlot();

    NumberAxis axis2 = new NumberAxis("Users");
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    plot.setDataset(1, theData2);
    plot.mapDatasetToRangeAxis(1, 1);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(0);
    renderer.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer.setSeriesStroke(1, new BasicStroke(2.0f));
    renderer = (XYLineAndShapeRenderer) renderer.clone();
    renderer.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer.setSeriesStroke(1, new BasicStroke(2.0f));
    plot.setRenderer(1, renderer);
    return chart;
}

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

protected void configureLineChart(final XYPlot plot) {
    final XYDataset linesDataset = createLinesDataset();
    if (linesDataset == null || linesDataset.getSeriesCount() == 0) {
        return;/*from  w w w.j a  v  a2s . c o  m*/
    }

    //Create Axis Objects
    final ValueAxis linesAxis;
    if (isSharedRangeAxis()) {
        linesAxis = plot.getRangeAxis();
    } else if (isThreeD()) {
        linesAxis = new NumberAxis3D(getSecondValueAxisLabel());
    } else {
        linesAxis = new NumberAxis(getSecondValueAxisLabel());
    }

    final XYItemRenderer lineRenderer;
    if (isThreeD()) {
        lineRenderer = new XYLine3DRenderer();
    } else {
        lineRenderer = new XYLineAndShapeRenderer();
    }

    plot.setRenderer(1, lineRenderer);
    plot.setDataset(1, linesDataset);
    plot.setRangeAxis(1, linesAxis);

    //map lines to second axis
    plot.mapDatasetToRangeAxis(1, 1);

    //set location of second axis
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
}