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

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

Introduction

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

Prototype

public void setDatasetRenderingOrder(DatasetRenderingOrder order) 

Source Link

Document

Sets the rendering order and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:be.nbb.demetra.dfm.output.simulation.RMSEGraphView.java

private JFreeChart createChart() {
    JFreeChart result = ChartFactory.createXYBarChart("", "", false, "", Charts.emptyXYDataset(),
            PlotOrientation.VERTICAL, false, false, false);
    result.setPadding(TsCharts.CHART_PADDING);
    result.getTitle().setFont(TsCharts.CHART_TITLE_FONT);

    XYPlot plot = result.getXYPlot();

    plot.setDataset(DFM_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(DFM_INDEX, dfmRenderer);
    plot.mapDatasetToDomainAxis(DFM_INDEX, 0);
    plot.mapDatasetToRangeAxis(DFM_INDEX, 0);

    plot.setDataset(ARIMA_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(ARIMA_INDEX, arimaRenderer);
    plot.mapDatasetToDomainAxis(ARIMA_INDEX, 0);
    plot.mapDatasetToRangeAxis(ARIMA_INDEX, 0);

    plot.setDataset(STDEV_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(STDEV_INDEX, stdevRenderer);
    plot.mapDatasetToDomainAxis(STDEV_INDEX, 0);
    plot.mapDatasetToRangeAxis(STDEV_INDEX, 0);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setRangeAxis(rangeAxis);/*ww w. j  a v a  2 s. c  o m*/

    NumberAxis domainAxis = new NumberAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setDomainAxis(domainAxis);

    return result;
}

From source file:io.github.mzmine.modules.plots.msspectrum.MsSpectrumPlotWindowController.java

public void initialize() {

    final JFreeChart chart = chartNode.getChart();
    final XYPlot plot = chart.getXYPlot();

    // Do not set colors and strokes dynamically. They are instead provided
    // by the dataset and configured in configureRenderer()
    plot.setDrawingSupplier(null);//from   www  .j a  v a 2 s.c o  m
    plot.setDomainGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor));
    plot.setRangeGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor));
    plot.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor));
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);

    // chart properties
    chart.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor));

    // legend properties
    LegendTitle legend = chart.getLegend();
    // legend.setItemFont(legendFont);
    legend.setFrame(BlockBorder.NONE);

    // set the X axis (m/z) properties
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setLabel("m/z");
    xAxis.setUpperMargin(0.03);
    xAxis.setLowerMargin(0.03);
    xAxis.setRangeType(RangeType.POSITIVE);
    xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));

    // set the Y axis (intensity) properties
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setLabel("Intensity");
    yAxis.setRangeType(RangeType.POSITIVE);
    yAxis.setAutoRangeIncludesZero(true);

    // set the fixed number formats, because otherwise JFreeChart sometimes
    // shows exponent, sometimes it doesn't
    DecimalFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();
    xAxis.setNumberFormatOverride(mzFormat);
    DecimalFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();
    yAxis.setNumberFormatOverride(intensityFormat);

    chartTitle = chartNode.getChart().getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    chartNode.setCursor(Cursor.CROSSHAIR);

    // Remove the dataset if it is removed from the list
    datasets.addListener((Change<? extends MsSpectrumDataSet> c) -> {
        while (c.next()) {
            if (c.wasRemoved()) {
                for (MsSpectrumDataSet ds : c.getRemoved()) {
                    int index = plot.indexOf(ds);
                    plot.setDataset(index, null);
                }
            }
        }
    });

    itemLabelsVisible.addListener((prop, oldVal, newVal) -> {
        for (MsSpectrumDataSet dataset : datasets) {
            int datasetIndex = plot.indexOf(dataset);
            XYItemRenderer renderer = plot.getRenderer(datasetIndex);
            renderer.setBaseItemLabelsVisible(newVal);
        }
    });

    legendVisible.addListener((prop, oldVal, newVal) -> {
        legend.setVisible(newVal);
    });

}

From source file:atencionurgencia.evolucion.grafic_sVitales.java

private void graficar() {
    final TimeSeriesCollection dataset1 = axisTaFC.createDatasetTA();
    final JFreeChart chart2 = ChartFactory.createTimeSeriesChart("", // chart title
            "HORA", // domain axis label
            "Tensin Arterial - TA (ppm)", // range axis label
            dataset1, // data

            true, // include legend
            true, // tooltips?
            false // URL generator?  Not required...
    );//from  w  w  w .  j  a va  2s.  com
    chart2.setBackgroundPaint(Color.white);
    final XYPlot plot = chart2.getXYPlot();
    plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF));
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    //        plot.set

    //        
    ////        final CategoryDataset dataset2 = axisTaFC.createDatasetFC();
    ////        plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 0);
    //        
    //        final DateAxis domainAxis = (DateAxis) plot.getDomainAxis();
    //        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    ////        final ValueAxis axis2 = new NumberAxis("Frecuencia Cardiaca - FC (ppm)");
    ////        plot.setRangeAxis(1, axis2);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    //        
    //        
    //        
    final ChartPanel chartPanel = new ChartPanel(chart2);
    chartPanel.setPreferredSize(new java.awt.Dimension(444, 358));//[598, 358][444, 358]
    jPanel4.removeAll();
    jPanel4.setLayout(new BorderLayout());
    jPanel4.add(chartPanel, BorderLayout.NORTH);
    jPanel4.repaint();
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.diagnostics.ApproximationSetPlot.java

@Override
protected void update() {
    XYSeriesCollection dataset = new XYSeriesCollection();

    for (ResultKey key : frame.getSelectedResults()) {
        NondominatedPopulation population = new EpsilonBoxDominanceArchive(EPSILON);

        for (Accumulator accumulator : controller.get(key)) {
            if (!accumulator.keySet().contains(metric)) {
                continue;
            }//from  w  ww.  jav  a  2s  . c  om

            List<?> list = (List<?>) accumulator.get(metric, accumulator.size(metric) - 1);

            for (Object object : list) {
                population.add((Solution) object);
            }
        }

        if (!population.isEmpty()) {
            XYSeries series = new XYSeries(key, false, true);

            for (Solution solution : population) {
                if (solution.getNumberOfObjectives() == 1) {
                    series.add(solution.getObjective(0), solution.getObjective(0));
                } else if (solution.getNumberOfObjectives() > 1) {
                    series.add(solution.getObjective(0), solution.getObjective(1));
                }
            }

            dataset.addSeries(series);
        }
    }

    JFreeChart chart = ChartFactory.createScatterPlot(metric, localization.getString("text.objective", 1),
            localization.getString("text.objective", 2), dataset, PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);

    for (int i = 0; i < dataset.getSeriesCount(); i++) {
        Paint paint = frame.getPaintHelper().get(dataset.getSeriesKey(i));

        renderer.setSeriesStroke(i, new BasicStroke(3f, 1, 1));
        renderer.setSeriesPaint(i, paint);
        renderer.setSeriesFillPaint(i, paint);
    }

    plot.setRenderer(renderer);

    //add overlay
    if (controller.getShowLastTrace() && (controller.getLastAccumulator() != null)
            && controller.getLastAccumulator().keySet().contains(metric)) {
        XYSeriesCollection dataset2 = new XYSeriesCollection();
        NondominatedPopulation population = new EpsilonBoxDominanceArchive(EPSILON);

        if (controller.getLastAccumulator().keySet().contains(metric)) {
            List<?> list = (List<?>) controller.getLastAccumulator().get(metric,
                    controller.getLastAccumulator().size(metric) - 1);

            for (Object object : list) {
                population.add((Solution) object);
            }
        }

        if (!population.isEmpty()) {
            XYSeries series = new XYSeries(localization.getString("text.last"), false, true);

            for (Solution solution : population) {
                series.add(solution.getObjective(0), solution.getObjective(1));
            }

            dataset2.addSeries(series);
        }

        XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(false, true);
        renderer2.setSeriesPaint(0, Color.BLACK);

        plot.setDataset(1, dataset2);
        plot.setRenderer(1, renderer2);
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    }

    removeAll();
    add(new ChartPanel(chart), BorderLayout.CENTER);
    revalidate();
    repaint();
}

From source file:jboost.visualization.HistogramFrame.java

private JFreeChart createHistogramChart() {

    XYBarRenderer renderer1 = new XYBarRenderer();
    renderer1.setSeriesPaint(0, Color.cyan);
    renderer1.setSeriesPaint(1, Color.pink);

    XYPlot histPlot = new XYPlot(histogramDataset, null, new NumberAxis("count"), renderer1);

    XYBarRenderer renderer2 = new XYBarRenderer();
    renderer2.setSeriesPaint(0, Color.green);
    renderer2.setSeriesPaint(1, Color.orange);
    renderer2.setUseYInterval(true);//from   w  w  w  .jav  a2  s . c o  m

    // weight and potential
    if (infoParser.isRobustBoost || infoParser.isAdaBoost || infoParser.isLogLossBoost) {
        StandardXYItemRenderer renderer3 = new StandardXYItemRenderer();
        renderer3.setSeriesPaint(0, Color.blue);
        renderer3.setSeriesPaint(1, Color.red);
        renderer3.setBaseStroke(new BasicStroke(2));

        StandardXYItemRenderer renderer4 = new StandardXYItemRenderer();
        renderer4.setSeriesPaint(0, Color.blue);
        renderer4.setSeriesPaint(1, Color.red);
        renderer4.setBaseStroke(
                new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 2, new float[] { 2 }, 0));

        histPlot.setDataset(1, weightDataset);
        histPlot.setRenderer(1, renderer3);

        histPlot.setDataset(2, potentialDataset);
        histPlot.setRenderer(2, renderer4);

        histPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    }

    XYPlot fluctPlot = new XYPlot(fluctDataset, null, new NumberAxis("bin"), renderer2);

    double initialLocation = (upper_limit + lower_limit) / 2.0;
    histMarker = new IntervalMarker(initialLocation, initialLocation);
    histPlot.addDomainMarker(histMarker, Layer.BACKGROUND);
    fluctPlot.addDomainMarker(histMarker, Layer.BACKGROUND);

    // plot.setBackgroundPaint(Color.lightGray);
    // plot.setDomainGridlinePaint(Color.white);
    // plot.setRangeGridlinePaint(Color.white);

    CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(new NumberAxis("score"));
    combinedPlot.setGap(10.0);

    // add the subplots...
    ValueAxis axis = new NumberAxis();
    axis.setRange(rawData.getMinRange(iter), rawData.getMaxRange(iter));
    combinedPlot.add(histPlot, 3);
    combinedPlot.add(fluctPlot, 1);
    combinedPlot.setOrientation(PlotOrientation.VERTICAL);
    combinedPlot.setDomainAxis(axis);

    JFreeChart chart = new JFreeChart("Histogram", JFreeChart.DEFAULT_TITLE_FONT, combinedPlot, false // legend
    );

    return chart;
}

From source file:MSUmpire.DIA.TargetMatchScoring.java

public void MixtureModeling() throws IOException {
    if (libTargetMatches.isEmpty()) {
        return;//w  w  w  .  j av  a2  s. com
    }
    int IDNo = 0;
    int decoyNo = 0;
    int modelNo = 0;
    double IDmean = 0d;
    double Decoymean = 0d;

    for (UmpireSpecLibMatch match : libIDMatches) {
        if (match.BestHit != null) {
            IDNo++;
            IDmean += match.BestHit.UmpireScore;
        }
    }

    decoyNo = decoyModelingList.size();
    for (PeakGroupScore peakGroupScore : decoyModelingList) {
        Decoymean += peakGroupScore.UmpireScore;
    }

    for (UmpireSpecLibMatch match : libTargetMatches) {
        //modelNo+= match.TargetHits.size();
        if (match.BestMS1Hit != null) {
            modelNo++;
        }
        if (match.BestMS2Hit != null) {
            modelNo++;
        }
    }

    Decoymean /= decoyNo;
    IDmean /= IDNo;

    PVector[] points = new PVector[modelNo];
    PVector[] centroids = new PVector[2];

    int idx = 0;
    for (UmpireSpecLibMatch match : libTargetMatches) {
        if (match.BestMS1Hit != null) {
            points[idx] = new PVector(1);
            points[idx].array[0] = match.BestMS1Hit.UmpireScore;
            idx++;
        }
        if (match.BestMS2Hit != null) {
            points[idx] = new PVector(1);
            points[idx].array[0] = match.BestMS2Hit.UmpireScore;
            idx++;
        }
        //            for(PeakGroupScore peakGroupScore : match.TargetHits){
        //                points[idx] = new PVector(1);
        //                points[idx].array[0] = match.BestMS2Hit.UmpireScore;
        //                idx++;
        //            }
    }

    MixtureModel mmc;
    centroids[0] = new PVector(1);
    centroids[0].array[0] = Decoymean;
    centroids[1] = new PVector(1);
    centroids[1].array[0] = IDmean;
    Vector<PVector>[] clusters = KMeans.run(points, 2, centroids);
    MixtureModel mm = ExpectationMaximization1D.initialize(clusters);
    mmc = ExpectationMaximization1D.run(points, mm);
    DecimalFormat df = new DecimalFormat("#.####");
    Logger.getRootLogger()
            .debug("----------------------------------------------------------------------------------------");
    Logger.getRootLogger().debug("No. of modeling points=" + modelNo);
    Logger.getRootLogger().debug("ID hits mean=" + df.format(IDmean));
    Logger.getRootLogger().debug("Decoy hits mean=" + df.format(Decoymean));
    //System.out.print("T-test: p-value=" + df.format(model.ttest.pValue).toString() + "\n");
    Logger.getRootLogger()
            .debug("Incorrect hits model mean=" + df.format(((PVector) mmc.param[0]).array[0]) + " variance="
                    + df.format(((PVector) mmc.param[0]).array[1]) + " weight=" + df.format(mmc.weight[0]));
    Logger.getRootLogger()
            .debug("Correct hits model mean=" + df.format(((PVector) mmc.param[1]).array[0]) + " variance="
                    + df.format(((PVector) mmc.param[1]).array[1]) + " weight=" + df.format(mmc.weight[1]));

    if (((PVector) mmc.param[0]).array[0] > ((PVector) mmc.param[1]).array[0]) {
        return;
    }

    float max = (float) (((PVector) mmc.param[1]).array[0] + 4 * Math.sqrt(((PVector) mmc.param[1]).array[1]));
    float min = (float) (((PVector) mmc.param[0]).array[0] - 4 * Math.sqrt(((PVector) mmc.param[0]).array[1]));

    IDNo = 0;
    decoyNo = 0;
    modelNo = 0;

    for (PeakGroupScore peakGroupScore : decoyModelingList) {
        if (peakGroupScore.UmpireScore > min && peakGroupScore.UmpireScore < max) {
            decoyNo++;
        }
    }

    for (UmpireSpecLibMatch match : libIDMatches) {
        if (match.BestHit != null && match.BestHit.UmpireScore > min && match.BestHit.UmpireScore < max) {
            IDNo++;
        }
    }

    for (UmpireSpecLibMatch match : libTargetMatches) {
        //targetNo += match.TargetHits.size();
        //decoyNo += match.DecoyHits.size();
        if (match.BestMS1Hit != null && match.BestMS1Hit.UmpireScore > min
                && match.BestMS1Hit.UmpireScore < max) {
            modelNo++;
        }
        if (match.BestMS2Hit != null && match.BestMS2Hit.UmpireScore > min
                && match.BestMS2Hit.UmpireScore < max) {
            modelNo++;
        }
        //modelNo += match.TargetHits.size();            
    }

    double[] IDObs = new double[IDNo];
    double[] DecoyObs = new double[decoyNo];
    double[] ModelObs = new double[modelNo];
    idx = 0;
    int didx = 0;
    int midx = 0;
    for (UmpireSpecLibMatch match : libIDMatches) {
        if (match.BestHit != null && match.BestHit.UmpireScore > min && match.BestHit.UmpireScore < max) {
            IDObs[idx++] = match.BestHit.UmpireScore;
        }
    }
    for (PeakGroupScore peakGroupScore : decoyModelingList) {
        if (peakGroupScore.UmpireScore > min && peakGroupScore.UmpireScore < max) {
            DecoyObs[didx++] = peakGroupScore.UmpireScore;
        }
    }

    for (UmpireSpecLibMatch match : libTargetMatches) {
        //            for(PeakGroupScore peak : match.TargetHits){
        //                ModelObs[midx++]=peak.UmpireScore;
        //            }
        if (match.BestMS1Hit != null && match.BestMS1Hit.UmpireScore > min
                && match.BestMS1Hit.UmpireScore < max) {
            ModelObs[midx++] = match.BestMS1Hit.UmpireScore;
        }
        if (match.BestMS2Hit != null && match.BestMS2Hit.UmpireScore > min
                && match.BestMS2Hit.UmpireScore < max) {
            ModelObs[midx++] = match.BestMS2Hit.UmpireScore;
        }
    }

    String pngfile = FilenameUtils.getFullPath(Filename) + "/" + FilenameUtils.getBaseName(Filename) + "_"
            + LibID + "_LibMatchModel.png";
    XYSeries model1 = new XYSeries("Incorrect matches");
    XYSeries model2 = new XYSeries("Correct matches");
    XYSeries model3 = new XYSeries("All target hits");

    String modelfile = FilenameUtils.getFullPath(pngfile) + "/" + FilenameUtils.getBaseName(pngfile)
            + "_ModelPoints.txt";
    FileWriter writer = new FileWriter(modelfile);
    writer.write("UScore\tModel\tCorrect\tDecoy\n");

    int NoPoints = 1000;
    double[] model_kde_x = new double[NoPoints];
    float intv = (max - min) / NoPoints;
    PVector point = new PVector(2);
    for (int i = 0; i < NoPoints; i++) {
        point.array[0] = max - i * intv;
        model_kde_x[i] = point.array[0];
        point.array[1] = mmc.EF.density(point, mmc.param[0]) * mmc.weight[0];
        model1.add(point.array[0], point.array[1]);
        point.array[1] = mmc.EF.density(point, mmc.param[1]) * mmc.weight[1];
        model2.add(point.array[0], point.array[1]);

    }

    KernelDensityEstimator kde = new KernelDensityEstimator();
    kde.SetData(ModelObs);
    double[] model_kde_y = kde.Density(model_kde_x);

    for (int i = 0; i < NoPoints; i++) {
        if (model_kde_x[i] > min && model_kde_x[i] < max) {
            point.array[0] = max - i * intv;
            model_kde_x[i] = point.array[0];
            model3.add(model_kde_x[i], model_kde_y[i]);
            writer.write(point.array[0] + "\t" + mmc.EF.density(point, mmc.param[0]) * mmc.weight[0] + "\t"
                    + mmc.EF.density(point, mmc.param[1]) * mmc.weight[1] + "\t" + model_kde_y[i] + "\n");
        }
    }
    writer.close();
    MixtureModelProb = new float[NoPoints + 1][3];
    float positiveaccu = 0f;
    float negativeaccu = 0f;

    MixtureModelProb[0][0] = (float) model2.getMaxX() + Float.MIN_VALUE;
    MixtureModelProb[0][1] = 1f;
    MixtureModelProb[0][2] = 1f;

    for (int i = 1; i < NoPoints + 1; i++) {
        float positiveNumber = model2.getY(NoPoints - i).floatValue();
        float negativeNumber = model1.getY(NoPoints - i).floatValue();
        MixtureModelProb[i][0] = model2.getX(NoPoints - i).floatValue();
        positiveaccu += positiveNumber;
        negativeaccu += negativeNumber;
        MixtureModelProb[i][2] = positiveNumber / (negativeNumber + positiveNumber);
        MixtureModelProb[i][1] = positiveaccu / (negativeaccu + positiveaccu);
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(model1);
    dataset.addSeries(model2);
    dataset.addSeries(model3);

    HistogramDataset histogramDataset = new HistogramDataset();
    histogramDataset.setType(HistogramType.SCALE_AREA_TO_1);
    histogramDataset.addSeries("ID hits", IDObs, 100);
    histogramDataset.addSeries("Decoy hits", DecoyObs, 100);
    //histogramDataset.addSeries("Model hits", ModelObs, 100);

    JFreeChart chart = ChartFactory.createHistogram(FilenameUtils.getBaseName(pngfile), "Score", "Hits",
            histogramDataset, PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = chart.getXYPlot();

    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setRange(min, max);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setForegroundAlpha(0.8f);
    chart.setBackgroundPaint(Color.white);

    XYLineAndShapeRenderer render = new XYLineAndShapeRenderer();
    //        render.setSeriesPaint(0, Color.DARK_GRAY);
    //        render.setSeriesPaint(1, Color.DARK_GRAY); 
    //        render.setSeriesPaint(2, Color.GREEN); 
    //        render.setSeriesShape(0, new Ellipse2D.Double(0, 0, 2, 2));
    //        render.setSeriesShape(1, new Ellipse2D.Double(0, 0, 2, 2));
    //        render.setSeriesShape(2, new Ellipse2D.Double(0, 0, 2.5f, 2.5f));
    //        render.setSeriesStroke(1, new BasicStroke(1.0f));
    //        render.setSeriesStroke(0, new BasicStroke(1.0f));
    //        render.setSeriesStroke(2, new BasicStroke(2.0f));
    plot.setDataset(1, dataset);
    plot.setRenderer(1, render);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    try {
        ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600);
    } catch (IOException e) {
    }
}

From source file:edu.unibonn.plotting.TimeSeriesPlotter_Sensors.java

private JFreeChart createChart(final XYDataset dataset, final XYDataset dataset_centroids,
        ArrayList<Cluster_KMeans> clusters) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Sensors", "Time", "Erlang", dataset, false, //t
            true, //t
            false //f
    );/*from w  w w . j  av  a  2 s  .  c  o m*/

    ChartUtilities.applyCurrentTheme(chart);

    //chart.setBackgroundPaint(Color.white);

    //        final StandardLegend sl = (StandardLegend) chart.getLegend();
    //        sl.setDisplaySeriesShapes(true);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    final XYItemRenderer renderer = plot.getRenderer();

    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        //rr.setPlotShapes(true);
        rr.setShapesFilled(true);
        rr.setItemLabelsVisible(true);
    }

    int temp_count = 0;

    //for (int i = 0; i < clusters.size(); i++)
    for (int i = 0; (i < 11) && (i < clusters.size()); i++) {
        Cluster_KMeans current_cluster = clusters.get(i);
        ArrayList<Sensor> member_time_series = current_cluster.getMembership();

        for (int j = 0; j < member_time_series.size(); j++) {
            renderer.setSeriesPaint(j + temp_count, getColor(i));
        }
        temp_count = temp_count + member_time_series.size();
    }

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));

    //final ValueAxis axis_y = plot.getRangeAxis();
    //axis_y.setRange(0, 20);

    plot.setDataset(1, dataset_centroids);
    plot.setRenderer(1, new StandardXYItemRenderer());

    for (int i = 0; (i < clusters.size()); i++) {
        //plot.getRenderer(1).setSeriesPaint(i, getColor(i));
        plot.getRenderer(1).setSeriesPaint(i, Color.BLACK);
        plot.getRenderer(1).setSeriesStroke(i, new BasicStroke(3.0f, BasicStroke.CAP_ROUND,
                BasicStroke.JOIN_ROUND, 1.0f, new float[] { 10.0f, 6.0f }, 0.0f));
    }

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    return chart;
}

From source file:edu.unibonn.kmeans.mapreduce.plotting.TimeSeriesPlotter_KMeans.java

/**
  * Creates a chart./*from   ww  w .j ava2  s  .  co  m*/
  * 
  * @param dataset  a dataset.
 * @param clusters 
  * 
  * @return A chart.
  */
//    private JFreeChart createChart(final XYDataset dataset, ArrayList<Cluster_DBScan> clusters) {
//
//        final JFreeChart chart = ChartFactory.createTimeSeriesChart(
//            "Sensors",
//            "Time", "Erlang",
//            dataset,
//            false, //t
//            true, //t
//            false //f
//        );
//
//        ChartUtilities.applyCurrentTheme(chart);
//        
//        //chart.setBackgroundPaint(Color.white);
//
////        final StandardLegend sl = (StandardLegend) chart.getLegend();
////        sl.setDisplaySeriesShapes(true);
//
//        final XYPlot plot = chart.getXYPlot();
//        plot.setBackgroundPaint(Color.WHITE);
//        plot.setDomainGridlinePaint(Color.white);
//        plot.setRangeGridlinePaint(Color.white);
////        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
//        plot.setDomainCrosshairVisible(true);
//        plot.setRangeCrosshairVisible(true);
//        
//        final XYItemRenderer renderer = plot.getRenderer();
//        
//        if (renderer instanceof StandardXYItemRenderer) 
//        {
//            final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
//            //rr.setPlotShapes(true);
//            rr.setShapesFilled(true);
//            rr.setItemLabelsVisible(true);
//        }
//
//        int temp_count = 0;
//        
//        //for (int i = 0; i < clusters.size(); i++)
//        for (int i = 0; (i < 11) && (i < clusters.size()); i++)
//      {
//         Cluster_DBScan current_cluster = clusters.get(i);   
//         ArrayList<Day_24d> member_time_series = current_cluster.getMembership();
//         
//         for (int j = 0; j < member_time_series.size(); j++)
//         {
//            renderer.setSeriesPaint(j+temp_count, getColor(i));
//         }
//         temp_count = temp_count + member_time_series.size();
//      }
//        
//        final DateAxis axis = (DateAxis) plot.getDomainAxis();    
//        axis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
//        
//        final ValueAxis axis_y = plot.getRangeAxis();
//        axis_y.setRange(0, 100);
//        
//        return chart;
//
//    }

private JFreeChart createChart(final XYDataset dataset, final XYDataset dataset_centroids,
        ArrayList<Cluster_KMeans> clusters) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Sensors", "Time", "Erlang", dataset, false, //t
            true, //t
            false //f
    );

    ChartUtilities.applyCurrentTheme(chart);

    //chart.setBackgroundPaint(Color.white);

    //        final StandardLegend sl = (StandardLegend) chart.getLegend();
    //        sl.setDisplaySeriesShapes(true);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    final XYItemRenderer renderer = plot.getRenderer();

    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        //rr.setPlotShapes(true);
        rr.setShapesFilled(true);
        rr.setItemLabelsVisible(true);
    }

    int temp_count = 0;

    //for (int i = 0; i < clusters.size(); i++)
    for (int i = 0; (i < 11) && (i < clusters.size()); i++) {
        Cluster_KMeans current_cluster = clusters.get(i);
        ArrayList<Day_24d> member_time_series = current_cluster.getMembership();

        for (int j = 0; j < member_time_series.size(); j++) {
            renderer.setSeriesPaint(j + temp_count, getColor(i));
        }
        temp_count = temp_count + member_time_series.size();
    }

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));

    //final ValueAxis axis_y = plot.getRangeAxis();
    //axis_y.setRange(0, 20);

    plot.setDataset(1, dataset_centroids);
    plot.setRenderer(1, new StandardXYItemRenderer());

    for (int i = 0; (i < clusters.size()); i++) {
        //plot.getRenderer(1).setSeriesPaint(i, getColor(i));
        plot.getRenderer(1).setSeriesPaint(i, Color.BLACK);
        plot.getRenderer(1).setSeriesStroke(i, new BasicStroke(3.0f, BasicStroke.CAP_ROUND,
                BasicStroke.JOIN_ROUND, 1.0f, new float[] { 10.0f, 6.0f }, 0.0f));
    }

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    return chart;
}

From source file:whitebox.stats.Kriging.java

/**
 * It gets the semivariogram type and bins list and draw a graph for them
 * TheoryVariogram should be called first
 *
 * @param bins//  w  w w.j a v a2 s .c  o m
 * @param variogram
 */
public void DrawSemivariogram(bin[][] bins, Variogram variogram) {
    XYSeriesCollection sampleCollct = new XYSeriesCollection();
    XYSeries series = new XYSeries("Sample Variogram");
    //        for (Iterator<bin> i = bins.iterator(); i.hasNext(); )
    //        {
    //            series.add(bins.get(j).Distance,bins.get(j).Value);
    //            i.next();
    //            j++;
    //        }
    XYLineAndShapeRenderer xylineshapRend = new XYLineAndShapeRenderer(false, true);
    CombinedRangeXYPlot combinedrangexyplot = new CombinedRangeXYPlot();
    for (int i = 0; i < bins[0].length; i++) {
        for (int k = 0; k < bins.length; k++) {
            if (!Double.isNaN(bins[k][i].Value)) {
                series.add(bins[k][i].Distance, bins[k][i].Value);
            }
        }
        sampleCollct.addSeries(series);
        double[][] res = CalcTheoreticalSVValues(variogram, series.getMaxX());
        XYSeries seriesTSV = new XYSeries("Theoretical Variogram");
        for (int l = 0; l < res.length; l++) {
            seriesTSV.add(res[l][0], res[l][1]);
        }
        XYSeriesCollection theorCollct = new XYSeriesCollection();
        theorCollct.addSeries(seriesTSV);

        XYDataset xydataset = sampleCollct;

        XYPlot xyplot1 = new XYPlot(xydataset, new NumberAxis(), null, xylineshapRend);

        xyplot1.setDataset(1, theorCollct);
        XYLineAndShapeRenderer lineshapRend = new XYLineAndShapeRenderer(true, false);
        xyplot1.setRenderer(1, lineshapRend);
        xyplot1.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
        combinedrangexyplot.add(xyplot1);
    }

    DecimalFormat df = new DecimalFormat("###,##0.000");
    String title = "Semivariogram (RMSE = " + df.format(Math.sqrt(variogram.mse)) + ")";
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, combinedrangexyplot, true);

    //        JFreeChart chart = ChartFactory.createScatterPlot(
    //            "Semivariogram", // chart title
    //            "Distance", // x axis label
    //            "Moment of Inertia", // y axis label
    //            result, // data  
    //            PlotOrientation.VERTICAL,
    //            true, // include legend
    //            true, // tooltips
    //            false // urls
    //            );
    // create and display a frame...
    ChartFrame frame = new ChartFrame("Semivariogram", chart);
    frame.pack();
    frame.setVisible(true);
}

From source file:replicatorg.app.ui.panels.ControlPanel.java

private ChartPanel makeChart() {
    JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, t0MeasuredDataset,
            PlotOrientation.VERTICAL, false, false, false);
    chart.setBorderVisible(false);/*from w  ww.j av  a 2  s. co  m*/
    chart.setBackgroundPaint(null);

    XYPlot plot = chart.getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setLowerMargin(0);
    axis.setFixedAutoRange(3L * 60L * 1000L); // auto range to three minutes

    TickUnits unitSource = new TickUnits();
    unitSource.add(new NumberTickUnit(60L * 1000L)); // minutes
    unitSource.add(new NumberTickUnit(1L * 1000L)); // seconds

    axis.setStandardTickUnits(unitSource);
    axis.setTickLabelsVisible(false); // We don't need to see the millisecond count
    axis = plot.getRangeAxis();
    axis.setRange(0, 300); // set temperature range from 0 to 300 degrees C so you can see overshoots 

    XYStepRenderer renderer = new XYStepRenderer();
    plot.setDataset(1, t0TargetDataset);
    plot.setRenderer(1, renderer);
    plot.getRenderer(1).setSeriesPaint(0, t0TargetColor);
    plot.getRenderer(0).setSeriesPaint(0, t0MeasuredColor);

    plot.setDataset(2, pMeasuredDataset);
    plot.setRenderer(2, new XYLineAndShapeRenderer(true, false));
    plot.getRenderer(2).setSeriesPaint(0, pMeasuredColor);
    plot.setDataset(3, pTargetDataset);
    plot.setRenderer(3, new XYStepRenderer());
    plot.getRenderer(3).setSeriesPaint(0, pTargetColor);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(400, 160));
    chartPanel.setOpaque(false);
    return chartPanel;
}