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:utils.HistogramFrame.java

/**
 * Loads the values provided in the constructor into a XYDataset for drawing the values.
 *//*from   www. j  a  va  2 s. c  o m*/
private void createDataset() {
    final XYSeries series = new XYSeries("data");
    for (int i = 0; i < this.values.length; i++)
        series.add(i, this.values[i]);
    this.dataset = new XYSeriesCollection(series);
}

From source file:serial.ChartFromSerial.java

/**
 * Creates new form JavaArduinoInterfacingAttempt
 *///w ww.  jav a  2  s .c o  m
public ChartFromSerial() {
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        System.out.println(e);
    }
    initComponents();

    //set autoscroll
    autoScroll_chkBx.setSelected(true);
    autoScrollEnabled = true;

    //create the graph
    defaultSeries = new XYSeries(graphName);
    defaultDataset = new XYSeriesCollection(defaultSeries);
    defaultChart = ChartFactory.createXYLineChart(graphName, xAxisLabel, yAxisLabel, defaultDataset);
    graph = new ChartPanel(defaultChart);
    chartPanel.add(graph, BorderLayout.CENTER);
    graph.setVisible(true);

    //create the text log
    text = new JTextArea();
    text.setEditable(false);
    textScrollPane = new JScrollPane(text);
    textScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    textPanel.add(textScrollPane, BorderLayout.CENTER);
    textScrollPane.setVisible(true);

    //Populate the combo box
    portNames = SerialPort.getCommPorts();
    while (portNames.length == 0) {
        if (JOptionPane.showConfirmDialog(rootPane, "No connected devices found.\nWould you like to refresh?",
                "Could not connect to any devices.", JOptionPane.YES_NO_OPTION,
                JOptionPane.ERROR_MESSAGE) == JOptionPane.NO_OPTION) {
            buttonsOff();
            return;
        } else {
            portNames = SerialPort.getCommPorts();
        }
    }
    portList_jCombo.removeAllItems();
    for (SerialPort portName : portNames) {
        portList_jCombo.addItem(portName.getSystemPortName());
    }
}

From source file:openomr.dataanalysis.XYChart.java

public XYChart(int size, int data[], String name) {
    XYSeries series = new XYSeries(name);
    for (int i = 0; i < size; i += 1)
        series.add(i, data[i]);//w w w . jav  a 2  s .c  om
    XYDataset xyDataset = new XYSeriesCollection(series);

    chart = ChartFactory.createXYAreaChart(name, "width", "# Pixels", xyDataset, PlotOrientation.HORIZONTAL,
            true, false, false);

}

From source file:org.jfree.data.general.HeatMapUtilities.java

/**
 * Returns a dataset containing one series that holds a copy of the (y, z)
 * data from one column (x-index) of the specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param column  the column (x) index./*  w  ww. ja v a 2s.  c  o m*/
 * @param seriesName  the series name (<code>null</code> not permitted).
 *
 * @return The dataset.
 */
public static XYDataset extractColumnFromHeatMapDataset(HeatMapDataset dataset, int column,
        Comparable seriesName) {
    XYSeries series = new XYSeries(seriesName);
    int rows = dataset.getYSampleCount();
    for (int r = 0; r < rows; r++) {
        series.add(dataset.getYValue(r), dataset.getZValue(column, r));
    }
    XYSeriesCollection result = new XYSeriesCollection(series);
    return result;
}

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

/**
 * A demonstration application showing an {@link XYSeries} where all the y-values are the same.
 *
 * @param title  the frame title./*from w w  w  . ja  v a  2s. c  o m*/
 */
public XYSeriesDemo2(final String title) {

    super(title);
    final XYSeries series = new XYSeries("Flat Data");
    series.add(1.0, 100.0);
    series.add(5.0, 100.0);
    series.add(4.0, 100.0);
    series.add(12.5, 100.0);
    series.add(17.3, 100.0);
    series.add(21.2, 100.0);
    series.add(21.9, 100.0);
    series.add(25.6, 100.0);
    series.add(30.0, 100.0);
    final XYSeriesCollection data = new XYSeriesCollection(series);
    final JFreeChart chart = ChartFactory.createXYLineChart("XY Series Demo 2", "X", "Y", data,
            PlotOrientation.VERTICAL, true, true, false);

    final XYPlot plot = (XYPlot) chart.getPlot();
    final NumberAxis axis = (NumberAxis) plot.getRangeAxis();
    axis.setAutoRangeIncludesZero(false);
    axis.setAutoRangeMinimumSize(1.0);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

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

/**
 * A demonstration application showing an XY series containing a null value.
 *
 * @param title  the frame title.//ww  w .  j  av a 2 s.co  m
 */
public XYSeriesDemo(final String title) {

    super(title);
    final XYSeries series = new XYSeries("Random Data");
    series.add(1.0, 500.2);
    series.add(5.0, 694.1);
    series.add(4.0, 100.0);
    series.add(12.5, 734.4);
    series.add(17.3, 453.2);
    series.add(21.2, 500.2);
    series.add(21.9, null);
    series.add(25.6, 734.4);
    series.add(30.0, 453.2);
    final XYSeriesCollection data = new XYSeriesCollection(series);
    final JFreeChart chart = ChartFactory.createXYLineChart("XY Series Demo", "X", "Y", data,
            PlotOrientation.VERTICAL, true, true, false);

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

}

From source file:com.unicornlabs.kabouter.reporting.PowerReport.java

public static void GeneratePowerReport(Date startDate, Date endDate) {
    try {/*w  ww  .  ja va2  s  . c o  m*/
        Historian theHistorian = (Historian) BusinessObjectManager.getBusinessObject(Historian.class.getName());
        ArrayList<String> powerLogDeviceIds = theHistorian.getPowerLogDeviceIds();

        Document document = new Document(PageSize.A4, 50, 50, 50, 50);

        File outputFile = new File("PowerReport.pdf");
        outputFile.createNewFile();

        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile));
        document.open();

        document.add(new Paragraph("Power Report for " + startDate.toString() + " to " + endDate.toString()));

        document.newPage();

        DecimalFormat df = new DecimalFormat("#.###");

        for (String deviceId : powerLogDeviceIds) {
            ArrayList<Powerlog> powerlogs = theHistorian.getPowerlogs(deviceId, startDate, endDate);
            double total = 0;
            double max = 0;
            Date maxTime = startDate;
            double average = 0;
            XYSeries series = new XYSeries(deviceId);
            XYDataset dataset = new XYSeriesCollection(series);

            for (Powerlog log : powerlogs) {
                total += log.getPower();
                if (log.getPower() > max) {
                    max = log.getPower();
                    maxTime = log.getId().getLogtime();
                }
                series.add(log.getId().getLogtime().getTime(), log.getPower());
            }

            average = total / powerlogs.size();

            document.add(new Paragraph("\nDevice: " + deviceId));
            document.add(new Paragraph("Average Power Usage: " + df.format(average)));
            document.add(new Paragraph("Maximum Power Usage: " + df.format(max) + " at " + maxTime.toString()));
            document.add(new Paragraph("Total Power Usage: " + df.format(total)));
            //Create a custom date axis to display dates on the X axis
            DateAxis dateAxis = new DateAxis("Date");
            //Make the labels vertical
            dateAxis.setVerticalTickLabels(true);

            //Create the power axis
            NumberAxis powerAxis = new NumberAxis("Power");

            //Set both axes to auto range for their values
            powerAxis.setAutoRange(true);
            dateAxis.setAutoRange(true);

            //Create the tooltip generator
            StandardXYToolTipGenerator ttg = new StandardXYToolTipGenerator("{0}: {2}",
                    new SimpleDateFormat("yyyy/MM/dd HH:mm"), NumberFormat.getInstance());

            //Set the renderer
            StandardXYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES, ttg,
                    null);

            //Create the plot
            XYPlot plot = new XYPlot(dataset, dateAxis, powerAxis, renderer);

            //Create the chart
            JFreeChart myChart = new JFreeChart(deviceId, JFreeChart.DEFAULT_TITLE_FONT, plot, true);

            PdfContentByte pcb = writer.getDirectContent();
            PdfTemplate tp = pcb.createTemplate(480, 360);
            Graphics2D g2d = tp.createGraphics(480, 360, new DefaultFontMapper());
            Rectangle2D r2d = new Rectangle2D.Double(0, 0, 480, 360);
            myChart.draw(g2d, r2d);
            g2d.dispose();
            pcb.addTemplate(tp, 0, 0);

            document.newPage();
        }

        document.close();

        JOptionPane.showMessageDialog(null, "Report Generated.");

        Desktop.getDesktop().open(outputFile);
    } catch (FileNotFoundException fnfe) {
        JOptionPane.showMessageDialog(null,
                "Unable To Open File For Writing, Make Sure It Is Not Currently Open");
    } catch (IOException ex) {
        Logger.getLogger(PowerReport.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(PowerReport.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:mainGUI.TrainingJFrame.java

private void initLineChartPanel() {
    series = new XYSeries("MSE");
    seriesCollection = new XYSeriesCollection(series);

    chart = ChartFactory.createXYLineChart("Training", "Epoch Number", "MSE", seriesCollection,
            PlotOrientation.VERTICAL, true, true, true);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);// w ww.j  ava2s .  c  o m
    renderer.setBaseStroke(new BasicStroke(3));
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(renderer);

    chartPanel = new ChartPanel(chart);
    chartPanel.setSize(chartContainerPanel.getWidth(), chartContainerPanel.getHeight());

    chartContainerPanel.add(chartPanel);
}

From source file:sturesy.votinganalysis.TimeChart.java

/**
 * Creates an XYSeries-ChartPanel// ww  w . j a v a2  s .  c o m
 * 
 * @param votes
 *            votes to use
 * @return ChartPanel
 */
private ChartPanel getXYSeriesChart(Set<Vote> votes) {

    final XYSeries series = new XYSeries(Localize.getString("label.votes.over.time"));

    if (votes.size() != 0) {
        double[] dubble = createArrayOfVotes(votes);

        for (int i = 0; i < dubble.length; i++) {
            series.add(i, dubble[i]);
        }
    }
    final XYSeriesCollection data = new XYSeriesCollection(series);

    final JFreeChart chart = ChartFactory.createXYLineChart(Localize.getString("label.votes.over.time"),
            Localize.getString("label.time.seconds"), Localize.getString("label.amount.votes"), data,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(_background);
    chart.getPlot().setNoDataMessage("NO DATA");

    chart.getXYPlot().getRenderer().setSeriesStroke(0,
            new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f));
    chart.getXYPlot().getRenderer().setSeriesPaint(0, new Color(255, 140, 0));

    chart.getXYPlot().getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    chart.getXYPlot().getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    ChartPanel chartpanel = new ChartPanel(chart);
    return chartpanel;
}

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

/**
 * Runs the test./*from ww w.java  2  s.  c o m*/
 */
public void run() {

    this.finished = false;

    // create a dataset...
    final XYSeries series = new XYSeries("Random Data");
    for (int i = 0; i < 1440; i++) {
        final double x = Math.random();
        final double y = Math.random();
        series.add(x, y);
    }
    final XYDataset data = new XYSeriesCollection(series);

    // create a scatter chart...
    final boolean withLegend = true;
    final JFreeChart chart = ChartFactory.createScatterPlot("Scatter plot timing", "X", "Y", data,
            PlotOrientation.VERTICAL, withLegend, false, false);

    final XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new XYDotRenderer());

    final BufferedImage image = new BufferedImage(400, 300, BufferedImage.TYPE_INT_RGB);
    final Graphics2D g2 = image.createGraphics();
    final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 400, 300);

    // set up the timer...
    final Timer timer = new Timer(10000, this);
    timer.setRepeats(false);
    int count = 0;
    timer.start();
    while (!this.finished) {
        chart.draw(g2, chartArea, null, null);
        System.out.println("Charts drawn..." + count);
        if (!this.finished) {
            count++;
        }
    }
    System.out.println("DONE");

}