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:org.jfree.chart.demo.XYAreaChartDemo.java

/**
 * Creates a new demo.//from www.  j av  a  2s .  c  om
 *
 * @param title  the frame title.
 */
public XYAreaChartDemo(final String title) {

    super(title);

    final XYSeries series1 = new XYSeries("Random 1");
    series1.add(new Integer(1), new Double(500.2));
    series1.add(new Integer(2), new Double(694.1));
    series1.add(new Integer(3), new Double(-734.4));
    series1.add(new Integer(4), new Double(453.2));
    series1.add(new Integer(5), new Double(500.2));
    series1.add(new Integer(6), new Double(300.7));
    series1.add(new Integer(7), new Double(734.4));
    series1.add(new Integer(8), new Double(453.2));

    final XYSeries series2 = new XYSeries("Random 2");
    series2.add(new Integer(1), new Double(700.2));
    series2.add(new Integer(2), new Double(534.1));
    series2.add(new Integer(3), new Double(323.4));
    series2.add(new Integer(4), new Double(125.2));
    series2.add(new Integer(5), new Double(653.2));
    series2.add(new Integer(6), new Double(432.7));
    series2.add(new Integer(7), new Double(564.4));
    series2.add(new Integer(8), new Double(322.2));

    final XYSeriesCollection dataset = new XYSeriesCollection(series1);
    dataset.addSeries(series2);

    final JFreeChart chart = createChart(dataset);

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

}

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

public void populate(XYPlot plot, AROTraceData analysis) {
    XYSeries series = new XYSeries(0);
    if (analysis != null) {

        // Get packet iterators
        List<PacketInfo> packets = analysis.getAnalyzerResult().getTraceresult().getAllpackets();
        final double maxTS = analysis.getAnalyzerResult().getTraceresult().getTraceDuration();

        final List<String> tooltipList = new ArrayList<String>(1000);

        Double zeroTime = null;/*from   w w w  .j  a  va  2  s  .  c om*/
        double lastTime = 0.0;
        double startTime = analysis.getAnalyzerResult().getFilter().getTimeRange().getBeginTime();
        for (Throughput t : throughputHelper.calculateThroughput(startTime, maxTS,
                analysis.getAnalyzerResult().getProfile().getThroughputWindow(), packets)) {

            double time = t.getTime();
            double kbps = t.getKbps();
            if (kbps != 0.0) {
                if (zeroTime != null && zeroTime.doubleValue() != lastTime) {
                    series.add(lastTime, 0.0);
                    tooltipList.add(MessageFormat.format(THROUGHPUT_TOOLTIP, 0.0));
                }
                // Add slot to data set
                series.add(time, kbps);

                tooltipList.add(MessageFormat.format(THROUGHPUT_TOOLTIP, kbps));
                zeroTime = null;
            } else {
                if (zeroTime == null) {
                    // Add slot to data set
                    series.add(time, kbps);

                    tooltipList.add(MessageFormat.format(THROUGHPUT_TOOLTIP, kbps));
                    zeroTime = Double.valueOf(time);
                }
            }

            lastTime = time;
        }
        plot.getRenderer().setBaseToolTipGenerator(new XYToolTipGenerator() {

            @Override
            public String generateToolTip(XYDataset dataset, int series, int item) {

                // Tooltip displays throughput value
                return tooltipList.get(item);
            }

        });
    }

    plot.setDataset(new XYSeriesCollection(series));
    //      return plot;
}

From source file:BaselinePlotGenerator.java

private JFreeChart createChart(String filename, NssBaseline nssBaseline) {

    XYSeries series = new XYSeries("");
    float[] baselineValues = nssBaseline.getBaselineValues();

    // plot subband values
    for (int i = 0; i < baselineValues.length; i++) {
        series.add(i, baselineValues[i]);
    }/*from ww  w  .j a v  a 2 s.co m*/

    // add a final point at the end with a zero Y value,
    // to force the y axis to display full scale
    series.add(baselineValues.length, 0.0);

    XYDataset data = new XYSeriesCollection(series);

    String title = "SonATA Baseline";
    String xAxisLabel = "Subband";
    String yAxisLabel = "Power";

    JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, data,
            PlotOrientation.VERTICAL, false, // legend 
            true, // tooltips
            false // urls
    );

    String filenameBase = new File(filename).getName();

    String subTitle1 = filenameBase;
    chart.addSubtitle(new TextTitle(subTitle1));

    DecimalFormat freqFormatter = new DecimalFormat("0000.000 MHz  ");
    String freqString = freqFormatter.format(nssBaseline.getCenterFreqMhz());

    DecimalFormat bandwidthFormatter = new DecimalFormat("0.00 MHz  ");
    String bandwidthString = bandwidthFormatter.format(nssBaseline.getBandwidthMhz());

    String subTitle2 = "Center Freq: " + freqString + "     Bandwidth: " + bandwidthString;
    chart.addSubtitle(new TextTitle(subTitle2));

    // move the data off of the axes 
    // by extending the minimum axis value

    XYPlot plot = (XYPlot) ((JFreeChart) chart).getPlot();
    double axisMarginPercent = 0.02;
    NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis();
    valueAxis.setLowerBound(-1.0 * valueAxis.getUpperBound() * axisMarginPercent);
    valueAxis = (NumberAxis) plot.getDomainAxis();
    valueAxis.setLowerBound(-1.0 * valueAxis.getUpperBound() * axisMarginPercent);
    return chart;

}

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

/**
 * Creates a new demo./*ww w.  ja v  a 2s . c o m*/
 *
 * @param title  the frame title.
 */
public XYAreaChartTest(final String title) {

    super(title);

    final XYSeries series1 = new XYSeries("Random 1");
    series1.add(new Integer(1), new Double(500.2));
    series1.add(new Integer(2), new Double(694.1));
    series1.add(new Integer(3), new Double(-734.4));
    series1.add(new Integer(4), new Double(453.2));
    series1.add(new Integer(5), new Double(500.2));
    series1.add(new Integer(6), new Double(300.7));
    series1.add(new Integer(7), new Double(734.4));
    series1.add(new Integer(8), new Double(453.2));

    final XYSeries series2 = new XYSeries("Random 2");
    series2.add(new Integer(1), new Double(700.2));
    series2.add(new Integer(2), new Double(534.1));
    series2.add(new Integer(3), new Double(323.4));
    series2.add(new Integer(4), new Double(125.2));
    series2.add(new Integer(5), new Double(653.2));
    series2.add(new Integer(6), new Double(432.7));
    series2.add(new Integer(7), new Double(564.4));
    series2.add(new Integer(8), new Double(322.2));

    final XYSeriesCollection dataset = new XYSeriesCollection(series1);
    dataset.addSeries(series2);

    final JFreeChart chart = createChart(dataset);

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

}

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

/**
 * Creates a sample dataset.//from  w w  w.  j  a v a 2s . c  om
 *
 * @return The dataset.
 */
private XYDataset createDataset() {

    final XYSeries series = new XYSeries("Zone 1");
    series.add(1.0, -0.5);
    series.add(5.0, -0.5);
    series.add(10.0, -0.4);
    series.add(15.0, -0.4);
    series.add(20.0, -0.3);
    series.add(25.0, -0.3);
    series.add(30.0, -0.2);
    series.add(35.0, -0.2);

    return new XYSeriesCollection(series);

}

From source file:aka.pirana.jdoc.JChart.java

private XYDataset SampleGenerator() {
    manager.getTransaction().begin();//w  w  w.j a v  a2s  .co  m
    CriteriaBuilder cb = manager.getCriteriaBuilder();
    CriteriaQuery<Consultation> query = cb.createQuery(Consultation.class);
    Root<Consultation> sm = query.from(Consultation.class);
    query.where(cb.equal(sm.get("patient.id"), id.toString()));
    TypedQuery<Consultation> q = manager.createQuery(query);
    List<Consultation> results = q.getResultList();
    XYSeries xyWeightSeries = new XYSeries("Weight");
    XYSeries xyFatSeries = new XYSeries("Fat");
    XYSeries xyMuscleSeries = new XYSeries("Muscle");
    XYSeries xyWaterSeries = new XYSeries("Water");
    int i = 2;
    results.stream().map((result) -> {
        xyWeightSeries.add(i, result.getC_weight());
        return result;
    }).map((result) -> {
        xyFatSeries.add(i, result.getC_gm());
        return result;
    }).map((result) -> {
        xyMuscleSeries.add(i, result.getC_mm());
        return result;
    }).forEach((result) -> {
        xyWaterSeries.add(i, result.getC_hm());
    });
    XYSeriesCollection xyseriescollection = new XYSeriesCollection(xyWeightSeries);
    xyseriescollection.addSeries(xyFatSeries);
    xyseriescollection.addSeries(xyMuscleSeries);
    xyseriescollection.addSeries(xyWaterSeries);
    return xyseriescollection;
}

From source file:org.interpss.chart.dist.LoadScheduleChart.java

public XYDataset createDataSet(final double[] dataAry, final String label) {
    final XYSeries series = new XYSeries(label);
    for (int i = 0; i < dataAry.length; i++) {
        series.add(i, dataAry[i]);// w w w  .  ja  v  a2s. c o  m
    }
    series.add(dataAry.length, voltDataAry[dataAry.length - 1]);
    return new XYSeriesCollection(series);
}

From source file:org.yooreeka.util.gui.XyLogGui.java

public XyLogGui(String title, double[] x, double[] y) {

    super(title);

    errMsg = new StringBuilder();
    setLoopInt(x.length);/*from  ww w .jav a 2s .  c  o m*/

    if (checkX(x) && checkY(x.length, y)) {

        XYSeries xydata = new XYSeries(title);

        for (int i = 0; i < loopInt; i++) {

            if (x[i] == C.ZERO_DOUBLE || x[i] < 0) {
                x[i] = C.SMALL_DOUBLE;
            }

            if (y[i] == C.ZERO_DOUBLE || y[i] < 0) {
                y[i] = C.SMALL_DOUBLE;
            }

            xydata.add(x[i], y[i]);
        }

        xycollection = new XYSeriesCollection(xydata);

        final JFreeChart chart = ChartFactory.createXYLineChart(title + " (XY Plot)", "X", "Y", xycollection,
                PlotOrientation.VERTICAL, true, true, false);

        final XYPlot plot = chart.getXYPlot();

        final NumberAxis domainAxis = new NumberAxis("x");
        plot.setDomainAxis(domainAxis);

        final NumberAxis logRangeAxis = new LogarithmicAxis("Log(y)");
        plot.setRangeAxis(logRangeAxis);

        chart.setBackgroundPaint(Color.white);
        plot.setOutlinePaint(Color.black);

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

    } else {
        System.err.println(errMsg.toString());
    }
}

From source file:com.anji.floatingeye.FloatingEyeDisplay.java

private void init(Java2DSurface surface, FloatingEye anEye) {
    eye = anEye;//from   w w  w  .jav  a2  s  .  c om

    // this frame has 3 sections - status, surface canvas, and eye canvas
    addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            setVisible(false);
            dispose();
        }
    });
    GridLayout mainLayout = new GridLayout(2, 1);
    mainLayout.setHgap(10);
    mainLayout.setVgap(10);
    getContentPane().setLayout(mainLayout);
    GridLayout topPanelLayout = new GridLayout(2, 1);
    topPanelLayout.setHgap(10);
    topPanelLayout.setVgap(10);
    Panel topPanel = new Panel(topPanelLayout);
    GridLayout bottomPanelLayout = new GridLayout(1, 2);
    bottomPanelLayout.setHgap(10);
    bottomPanelLayout.setVgap(10);
    Panel bottomPanel = new Panel(bottomPanelLayout);

    // 1 - status area
    statusArea = new TextArea("", 1, 1, TextArea.SCROLLBARS_VERTICAL_ONLY);
    statusArea.setEditable(false);
    statusArea.setFont(new Font("Dialog", Font.PLAIN, 10));
    statusArea.setSize(new Dimension(IMG_WIDTH * 2, IMG_HEIGHT / 2));

    // 2 - affinity history chart
    XYSeriesCollection seriesCollection = new XYSeriesCollection(affinitySeries);
    JFreeChart chart = ChartFactory.createXYLineChart("affinity history", "step", "affinity", seriesCollection,
            PlotOrientation.VERTICAL, false, false, false);
    ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis();
    rangeAxis.setAutoRange(false);
    rangeAxis.setRange(0d, 1d);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(IMG_WIDTH * 2, IMG_HEIGHT / 2));

    // 3 - surface canvas
    surfaceCanvas = new SurfaceCanvas(surface, eye, IMG_WIDTH, IMG_HEIGHT);
    surfaceCanvas.setBackground(Color.WHITE);

    // 4 - eye canvas
    eyeCanvas = new EyeCanvas(eye, IMG_WIDTH, IMG_HEIGHT);
    eyeCanvas.setBackground(Color.WHITE);

    topPanel.add(statusArea);
    topPanel.add(chartPanel);
    bottomPanel.add(surfaceCanvas);
    bottomPanel.add(eyeCanvas);
    getContentPane().add(topPanel);
    getContentPane().add(bottomPanel);

    pack();
}

From source file:RLCcircuit.RLCcircuitJFrame.java

public JFreeChart getResultChart() {

    XYSeries series1 = new XYSeries("Resistor");
    XYSeries series2 = new XYSeries("Inductor");
    XYSeries series3 = new XYSeries("Capacitor");

    for (double i = 0 + time; i < 100 + time; i++) {
        ValueCaculate(i / 1000.);//from w  w w.  jav  a2  s .  c o  m
        series1.add(i, Rvoltage);
    }

    for (double i = 0 + time; i < 100 + time; i++) {
        ValueCaculate(i / 1000.);
        series2.add(i, Lvoltage);
    }

    for (double i = 0 + time; i < 100 + time; i++) {
        ValueCaculate(-i / 1000.);
        series3.add(i, Cvoltage);
    }

    XYSeriesCollection data1 = new XYSeriesCollection(series1);
    XYSeriesCollection data2 = new XYSeriesCollection(series2);
    XYSeriesCollection data3 = new XYSeriesCollection(series3);

    final JFreeChart chart = ChartFactory.createXYLineChart("Time-Voltage Graph", "Time", "Voltage", data1,
            PlotOrientation.VERTICAL, true, false, false);
    chart.setBackgroundPaint(null);
    XYPlot plot = chart.getXYPlot();
    plot.setDataset(1, data2);
    plot.setDataset(2, data3);

    XYLineAndShapeRenderer Renderer1 = new XYLineAndShapeRenderer();
    XYLineAndShapeRenderer Renderer2 = new XYLineAndShapeRenderer();
    XYLineAndShapeRenderer Renderer3 = new XYLineAndShapeRenderer();
    plot.setRenderer(0, Renderer1);
    plot.setRenderer(1, Renderer2);
    plot.setRenderer(2, Renderer3);
    Renderer1.setSeriesShapesVisible(0, false);
    Renderer2.setSeriesShapesVisible(0, false);
    Renderer3.setSeriesShapesVisible(0, false);

    plot.setBackgroundPaint(Color.black);
    plot.getDomainAxis().setVisible(false);
    plot.getRangeAxis().setVisible(false);
    plot.getRangeAxis().setRange(-20, 20);

    //chart.plotChanged(new PlotChangeEvent(plot));

    return chart;
}