Example usage for org.jfree.data.xy XYSeriesCollection XYSeriesCollection

List of usage examples for org.jfree.data.xy XYSeriesCollection XYSeriesCollection

Introduction

In this page you can find the example usage for org.jfree.data.xy XYSeriesCollection XYSeriesCollection.

Prototype

public XYSeriesCollection(XYSeries series) 

Source Link

Document

Constructs a dataset and populates it with a single series.

Usage

From source file:syg_package01.PanelRysunek_Wykres.java

private void initGUI() {
    try {/* w ww .  jav a 2 s . co m*/
        GridLayout thisLayout = new GridLayout(1, 1);
        thisLayout.setHgap(5);
        thisLayout.setVgap(5);
        thisLayout.setColumns(1);
        this.setLayout(thisLayout);
        setPreferredSize(new Dimension(400, 300));

        if (this.wykres) {

            XYSeries series = new XYSeries("Wykres");
            double punkt;
            double ta = this.sygnalWyswietlany.gett1();

            if (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.CIAGLY
                    || sygnalWyswietlany.getPunktyY().size() <= 0) {
                punkt = this.sygnalWyswietlany.gett1();
                while (ta <= this.sygnalWyswietlany.gett1() + this.sygnalWyswietlany.getd()) {
                    punkt = this.sygnalWyswietlany.wykres_punkty(punkt, ta);
                    this.sygnalWyswietlany.setPunktyY(punkt);
                    series.add(ta, punkt);
                    if (this.sygnalWyswietlany.gettyp() < 10)
                        ta = ta + this.sygnalWyswietlany.getkroczek();
                    else
                        ta = ta + this.sygnalWyswietlany.getkroczek() * 10;
                }
            } else if (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.DYSKRETNY
                    && sygnalWyswietlany.getPunktyY().size() > 0) {
                punkt = sygnalWyswietlany.getPunktzindexu(0);
                int iloscProbek = (int) (this.sygnalWyswietlany.getPunktyY().size());
                for (int i = 1; i < iloscProbek; i++) {
                    punkt = this.sygnalWyswietlany.getPunktzindexu(i);
                    series.add(ta, punkt);
                    // if (this.sygnalWyswietlany.gettyp() < 10)
                    // ta = ta + this.sygnalWyswietlany.getkroczek();
                    // else
                    ta = ta + this.sygnalWyswietlany.getkroczek();
                }
            }

            XYSeriesCollection dataset = new XYSeriesCollection(series);
            JFreeChart chart;

            if ((this.sygnalWyswietlany.gettyp() < 10)
                    && (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.CIAGLY)) {
                chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL,
                        true, true, true);

                final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
                renderer.setSeriesLinesVisible(0, false);
            } else {
                chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL,
                        true, true, true);

                final XYPlot plot = chart.getXYPlot();
                final XYDotRenderer renderer = new XYDotRenderer();
                renderer.setDotHeight(3);
                renderer.setDotWidth(3);
                plot.setRenderer(renderer);

                final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
                rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            }

            ChartPanel chartpanel = new ChartPanel(chart);
            chartpanel.setDomainZoomable(true);

            this.add(chartpanel);
        }

        Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:net.bioclipse.seneca.views.BestStructureView.java

public void createPartControl(Composite parent) {
    SashForm sash = new SashForm(parent, SWT.VERTICAL);
    jcpwidget = new JChemPaintEditorWidget(sash, SWT.PUSH);
    Composite contChartcomposite = new Composite(sash, SWT.EMBEDDED);
    FillLayout layout = new FillLayout(SWT.VERTICAL);
    contChartcomposite.setLayout(layout);
    fileTableFrame = SWT_AWT.new_Frame(contChartcomposite);

    String xAxisLabel = "Steps";
    String yAxisLabel = "Temperature/Score";
    String title = "Annealing progress";
    XYSeries series = new XYSeries("Signal");
    for (int i = 0; i < (maxSteps != 0 ? maxSteps : temps.size()); i++) {
        if (i < temps.size())
            series.add(i, temps.get(i));
        else/*  w  w w . j a  va 2  s . c  om*/
            series.add(i, 0);
    }

    XYDataset xyDataset = new XYSeriesCollection(series);
    continuousChart = ChartFactory.createXYAreaChart(title, xAxisLabel, yAxisLabel, xyDataset,
            PlotOrientation.VERTICAL, false, true, false);
    continuousChart.setAntiAlias(false);

    XYPlot continuousPlot = continuousChart.getXYPlot();

    continuousPlot.setRenderer(new StandardXYItemRenderer());
    ChartPanel chart = new ChartPanel(continuousChart);
    fileTableFrame.add(chart);
    //fileTableFrame.validate();
    //fileTableFrame.repaint();

}

From source file:chart.JChart.java

/**
 * Creates a sample dataset.//from w  ww.j  av a2 s.  c o m
 *
 * @return A sample dataset.
 */
private XYDataset createDataset(NTimeSeries data) {
    final XYSeries series = new XYSeries("");
    List<Double> lst = (data.getRawData() == null || data.getRawData().isEmpty()) ? data.getData()
            : data.getRawData();
    int size = lst.size();
    for (int i = 0; i < size; i++) {
        try {
            series.add(i, lst.get(i));
        } catch (SeriesException e) {
            System.err.println("Error adding to series");
        }
    }
    return new XYSeriesCollection(series);
}

From source file:gui.grafica.estadisticas.GUIPanelGrafica.java

public BufferedImage creaImagen() {
    XYSeries series = new XYSeries("Evolucion");
    for (int i = 0; i < listaEjeY.size(); i++) {
        Date date = listaEjeX.get(i);
        date.getTime();/*  ww  w  .  ja v a  2 s .c o  m*/
        series.add(date.getTime(), listaEjeY.get(i));
    }
    //        series.add(4, 23);
    //        series.add(2, 34);
    //        series.add(3, 51);
    //        series.add(4, 67);
    //        series.add(5, 89);
    //        series.add(6, 121);
    //        series.add(7, 137);
    XYDataset juegoDatos = new XYSeriesCollection(series);
    log.info(listaEjeX.toString());
    JFreeChart chart = ChartFactory.createXYLineChart(titulo, leyendaEjeX, leyendaEjeY, juegoDatos,
            PlotOrientation.VERTICAL, false, false, true // Show legend
    );
    log.info("Valor de Width:" + getWidth());
    log.info("Valor de Heigth:" + getHeight());
    BufferedImage image = chart.createBufferedImage(getWidth(), getHeight());
    return image;
}

From source file:org.spantus.exp.segment.exec.DrawSegmentComparision.java

/**
 * initialize/*w w w. jav  a 2 s  . c om*/
 */
public void init() {
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Time"));
    plot.setGap(10.0);
    plot.setOrientation(PlotOrientation.VERTICAL);

    XYSeries[] seriesArr = createSeries(getWavName(), getMarkerName());
    for (XYSeries series : seriesArr) {
        final XYSeriesCollection data1 = new XYSeriesCollection(series);
        final XYItemRenderer renderer1 = new StandardXYItemRenderer();
        final NumberAxis rangeAxis1 = new NumberAxis(series.getDescription());
        final XYPlot subplot = new XYPlot(data1, null, rangeAxis1, renderer1);
        plot.add(subplot, 1);
    }

    final JFreeChart chart = new JFreeChart("Segmentation Result", JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    final ChartPanel chartPanel = new ChartPanel(chart);
    setContentPane(chartPanel);
    chartPanel.setPreferredSize(new Dimension(500, 270));
}

From source file:com.wattzap.view.graphs.MMPGraph.java

public MMPGraph(XYSeries series) {
    super();//from   w w w.j  a v  a 2s  .c  o m

    NumberAxis yAxis = new NumberAxis(userPrefs.messages.getString("poWtt"));
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    double maxY = series.getMaxY();
    yAxis.setRange(0, maxY + 20);
    yAxis.setTickLabelPaint(Color.white);
    yAxis.setLabelPaint(Color.white);

    LogAxis xAxis = new LogAxis(userPrefs.messages.getString("time"));
    xAxis.setTickLabelPaint(Color.white);
    xAxis.setBase(4);
    xAxis.setAutoRange(false);

    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    xAxis.setRange(1, series.getMaxX() + 500);
    xAxis.setNumberFormatOverride(new NumberFormat() {

        @Override
        public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {

            long millis = (long) number * 1000;

            if (millis >= 60000) {
                return new StringBuffer(String.format("%d m %d s",
                        TimeUnit.MILLISECONDS.toMinutes((long) millis),
                        TimeUnit.MILLISECONDS.toSeconds((long) millis)
                                - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis))));
            } else {
                return new StringBuffer(String.format("%d s",

                        TimeUnit.MILLISECONDS.toSeconds((long) millis)
                                - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis))));
            }
        }

        @Override
        public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
            return new StringBuffer(String.format("%s", number));
        }

        @Override
        public Number parse(String source, ParsePosition parsePosition) {
            return null;
        }
    });

    XYPlot plot = new XYPlot(new XYSeriesCollection(series), xAxis, yAxis,
            new XYLineAndShapeRenderer(true, false));

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

    chart.setBackgroundPaint(Color.gray);
    plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.darkGray);
    /*plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);*/

    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickLabelPaint(Color.white);
    domainAxis.setLabelPaint(Color.white);

    chartPanel = new ChartPanel(chart);
    chartPanel.setSize(100, 800);
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setBackground(Color.gray);

    setLayout(new BorderLayout());
    add(chartPanel, BorderLayout.CENTER);
    setBackground(Color.black);
    chartPanel.revalidate();
    setVisible(true);
}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.dec.LeastSquaresLineDecorator.java

@Override
public void decorate(JDialog aOwner, JFreeChart aChart, ComplexParamVisualizer aVisualizer, boolean aVerbose) {
    clearDataset(aChart, LeastSquaresLineDecorator.seriesName);

    final Point2D.Double[] dataPoints = JFreeChartConn.extractData(aChart);
    if (dataPoints.length < 2) {
        // Error - not enough data points
        if (aVerbose) {
            Utils.showErrorBox(aOwner, Messages.DT_FIT, Messages.SM_FITLINENODATA);
        }// w w  w  . j  av a2 s  .  co  m
        return;
    }
    coefs = Fitter.leastSquaresLineFit(dataPoints);

    if (coefs != null) {
        final XYSeries newData = createFittingData(dataPoints, isLinear(aVisualizer.getSettings()));
        final XYPlot plot = aChart.getXYPlot();
        int i = getDatasetIndex(plot, LeastSquaresLineDecorator.seriesName);
        if (i == -1) {
            i = createDataset(plot);
        }
        plot.setDataset(i, new XYSeriesCollection(newData));

        if (aVerbose) {
            // Compute correlation
            final int count = dataPoints.length;
            final double[] s1 = new double[count];
            final double[] s2 = new double[count];
            for (int j = 0; j < count; ++j) {
                s1[j] = dataPoints[j].y;
                s2[j] = valueAt(dataPoints[j].x);
            }
            Double corr = null;
            Double rsquared = null;
            try {
                corr = new Double(Fitter.computeCorr(s1, s2));
            } catch (ArithmeticException ex) {
                // Correlation could not be computed; ignore
            }
            try {
                rsquared = new Double(Fitter.computeRSquared(s1, s2));
            } catch (ArithmeticException ex) {
                // R-Squared could not be computed; ignore
            }

            // Inform the user what the coefficients are
            showReport(aOwner, corr, rsquared);
        }
    } else {
        // Could not fit a line
        if (aVerbose) {
            Utils.showErrorBox(aOwner, Messages.DT_FIT, Messages.SM_FITLINEERROR);
        }
    }
}

From source file:gui.DendrogramChart.java

private void setChartData(JFreeChart chart, boolean log) {
    XYSeries series = new XYSeries("Similarity vs No. of Groups");

    double rSim = d.getRootSimilarity();
    double diff = 1 - rSim;

    // TODO: What causes this?
    if (diff == 0)
        return;/*from   w w w .  j  a  va2 s  .c o  m*/

    for (double sim = rSim; sim <= 1.0; sim += (diff / 50)) {
        series.add(sim, d.getGroupCount(sim));
    }

    XYSeriesCollection data = new XYSeriesCollection(series);
    chart.getXYPlot().setDataset(data);
}

From source file:logica_controladores.controlador_estadistica.java

public static void grafica_reorden(JPanel panel_grafica_orden, Inventario inventario, JLabel lbLinea) {
    XYSeries serie_2 = null;/*from   ww  w  .  j  av a 2  s.co  m*/
    XYDataset datos;
    JFreeChart linea;

    serie_2 = new XYSeries("graficas relacion gastos-reorden");

    for (int i = 0; i < inventario.getGastos().size(); i++) {
        serie_2.add(inventario.getGastos().get(i).getReorden(), inventario.getGastos().get(i).getGastos());
    }
    datos = new XYSeriesCollection(serie_2);
    linea = ChartFactory.createXYLineChart("grafica representativa de reordenes por corrida", "punto de orden",
            "gastos", datos, PlotOrientation.VERTICAL, true, true, true);
    BufferedImage graficoLinea = linea.createBufferedImage(panel_grafica_orden.getWidth(),
            panel_grafica_orden.getHeight());
    lbLinea.setSize(panel_grafica_orden.getSize());
    lbLinea.setIcon(new ImageIcon(graficoLinea));
    panel_grafica_orden.updateUI();
}

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);
            }//w ww. j  av a2s .co m
        }
        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");
}