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() 

Source Link

Document

Constructs an empty dataset.

Usage

From source file:historyView.HistoryJFrame.java

/**
 * Creates new form HistoryJFrame//from  w  w w . j a  va2  s  .  co m
 */
public HistoryJFrame() {
    initComponents();
    //set window in the center of the screen
    //Get the size of the screen
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    //Determine the new location of the window
    int w = this.getSize().width;
    int h = this.getSize().height;
    int x = (dim.width - w) / 2;
    int y = (dim.height - h) / 2;
    //Move the window
    this.setLocation(x, y);

    XYSeries breathingSeries = new XYSeries("Breathing Rate");
    XYSeries oxygenSeries = new XYSeries("Oxygen");
    XYSeries temperatureSeries = new XYSeries("Temperature");
    XYSeries bloodPressureSeries = new XYSeries("Blood Pressure");
    XYSeries heartRateSeries = new XYSeries("Heart Rate");

    // add date to all the series
    for (Map.Entry<String, PatientData> entry : model.getSelectedPatient().data.entrySet()) {
        breathingSeries.add(Double.parseDouble(entry.getKey()), entry.getValue().getBreathing());
        oxygenSeries.add(Double.parseDouble(entry.getKey()), entry.getValue().getOxygen());
        temperatureSeries.add(Double.parseDouble(entry.getKey()), entry.getValue().getTemperature());
        bloodPressureSeries.add(Double.parseDouble(entry.getKey()), entry.getValue().getBloodPressure());
        heartRateSeries.add(Double.parseDouble(entry.getKey()), entry.getValue().getHeartRate());
    }

    // Add the series to your data set
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(breathingSeries);
    dataset.addSeries(oxygenSeries);
    dataset.addSeries(temperatureSeries);
    dataset.addSeries(bloodPressureSeries);
    dataset.addSeries(heartRateSeries);

    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart("XY Chart", // Title
            "time(s)", // x-axis Label
            "Rate", // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );

    this.setLayout(new java.awt.BorderLayout());
    ChartPanel CP = new ChartPanel(chart);
    chart.getPlot().setBackgroundAlpha(1);
    chart.getPlot().setBackgroundPaint(Color.BLUE);

    HistoryButtonsJPanel buttonPanel = new HistoryButtonsJPanel();

    ChartUtilities.applyCurrentTheme(chart);
    this.add(CP, BorderLayout.CENTER);
    this.add(buttonPanel, BorderLayout.PAGE_END);
    this.validate();
}

From source file:org.cyberoam.iview.charts.XYLine.java

/**
 * This method generates JFreeChart instance for XYLine chart with iView customization.
 * @param reportID specifies that for which report Chart is being prepared.
 * @param rsw specifies data set which would be used for the Chart
 * @param requeest used for Hyperlink generation from URL.
 * @return jfreechart instance with iView Customization.
 *//*w ww.  ja v  a2  s.c o m*/
public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) {
    ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID);
    JFreeChart chart = null;
    try {
        ReportColumnBean reportColumnBean = null;
        GraphBean graphBean = null;
        DataLinkBean dataLinkBean = null;
        XYDataset dataset = null;
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        XYSeries series = new XYSeries(reportBean.getTitle());
        graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());//Getting GraphBean
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getXColumnId());//getting ReportColumnBean For X Axis
        String xColumnDBname = reportColumnBean.getDbColumnName();
        String xColumnName = reportColumnBean.getColumnName();
        //Wheather DataLink is Given For X Axis column
        if (reportColumnBean.getDataLinkId() != -1) {
            dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId());
        }
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getYColumnId());
        String yColumnDBname = reportColumnBean.getDbColumnName();
        String yColumnName = reportColumnBean.getColumnName();
        //if DataLink is not Given For X Axis column then Check of Y Axis Column
        if (dataLinkBean == null && reportColumnBean.getDataLinkId() != -1) {
            dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId());
        }
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getZColumnId());
        String zColumnDbname = reportColumnBean.getDbColumnName();
        //Preparing DataSet
        String data = "";
        rsw.beforeFirst();
        while (rsw.next()) {
            data = rsw.getString(xColumnDBname);
            series.add(Long.parseLong((data).substring(data.length() - 2)),
                    new Long(rsw.getLong(yColumnDBname)).longValue());
        }
        seriesCollection.addSeries(series);

        dataset = seriesCollection;
        // create the chart...
        chart = ChartFactory.createXYLineChart("", // chart title
                "", // domain axis label
                "", seriesCollection, // data
                PlotOrientation.VERTICAL, // orientation
                false, // include legend
                true, // tooltips?
                false // URLs?
        );
        /*
         * Additional iView Customization.
         */
        //Set the background color for the chart...
        chart.setBackgroundPaint(Color.white);

        //Get a reference to the plot for further customisation...
        XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(new Color(245, 245, 245));
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setForegroundAlpha(0.7f);

        //Set the range axis to display integers only...
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        if (reportColumnBean.getColumnFormat() == TabularReportConstants.BYTE_FORMATTING) {
            rangeAxis.setTickUnit(new ByteTickUnit(rangeAxis.getUpperBound() / 4));
        }
        rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
        rangeAxis.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 10));
        rangeAxis.setTickLabelsVisible(true);
        rangeAxis.setTickMarksVisible(false);
        rangeAxis.setAxisLineVisible(false);

        Axis domainAxis = plot.getDomainAxis();
        domainAxis.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 10));
        domainAxis.setTickMarksVisible(false);
        domainAxis.setAxisLineVisible(false);

        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
        renderer.setSeriesPaint(0, Color.DARK_GRAY);
        renderer.setSeriesStroke(0, new BasicStroke(1));
    } catch (Exception e) {
        e.printStackTrace();
    }

    return chart;
}

From source file:web.diva.server.unused.ProfilePlotGenerator.java

/**
 *
 * @return dataset.//from w  w w.  j ava  2s. co  m
 */
private XYDataset createDataset(Number[][] pointsData) {

    final XYSeriesCollection dataset = new XYSeriesCollection();

    for (int x = 0; x < pointsData.length; x++) {
        XYSeries series = new XYSeries(x);
        Number[] data = pointsData[x];
        for (int y = 0; y < data.length; y++) {
            series.add(y, data[y]);
        }

        dataset.addSeries(series);

    }
    return dataset;

}

From source file:playground.benjamin.scenarios.zurich.analysis.charts.BkDeltaUtilsChart.java

private XYSeriesCollection createNeededDataset() {
    //instancing the dataset 
    XYSeriesCollection ds = new XYSeriesCollection();

    ds.addSeries(this.createSeries("delta utils over personal income",
            personalIncome2Scores(populationInformation)));
    return ds;/*w w w .  ja  va 2  s . c o m*/
}

From source file:playground.benjamin.scenarios.zurich.analysis.charts.BkDeltaUtilsQuantilesChart.java

private XYSeriesCollection createNeededDataset() {
    //instancing the dataset 
    XYSeriesCollection ds = new XYSeriesCollection();

    ds.addSeries(this.createSeries("delta utils over income quantiles",
            personalIncomeInQuantiles2Scores(populationInformation)));
    return ds;//  w  ww.j a v a 2  s.  co  m
}

From source file:au.edu.jcu.kepler.hydrant.JFreeChartPlot.java

public JFreeChartPlot(PlotterBase plotterBase) {
    _plotterBase = plotterBase;//ww w .  j  a v  a  2s .com
    _dataset = new XYSeriesCollection();
    _chart = ChartFactory.createXYLineChart(getName(), "", "", _dataset, PlotOrientation.VERTICAL, true, false,
            false);
    String value = plotterBase.legend.getExpression();
    _legend = new ArrayList<String>();
    if ((value != null) && !value.trim().equals("")) {
        StringTokenizer tokenizer = new StringTokenizer(value, ",");
        while (tokenizer.hasMoreTokens()) {
            _legend.add(tokenizer.nextToken().trim());
        }
    }
}

From source file:com.mycompany.istudy.principalservices.GraphicalView.java

private XYDataset createDataset(Map<Double, Double> investedHoursPerWeek,
        Map<Double, Double> hoursToBeInvested) {
    final XYSeries moduleToWeek = new XYSeries("Actual Performance");

    investedHoursPerWeek.entrySet().stream().forEach((pair) -> {
        moduleToWeek.add((double) pair.getKey(), (double) pair.getValue());
    });/*from w  w  w.  java 2  s . c om*/
    final XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(moduleToWeek);

    final XYSeries optimalWorkload = new XYSeries("Optimal Performance ");

    hoursToBeInvested.entrySet().stream().forEach((pair) -> {
        optimalWorkload.add((double) pair.getKey(), (double) pair.getValue());
    });
    dataset.addSeries(optimalWorkload);
    return dataset;
}

From source file:com.joey.software.plottingToolkit.PlotingToolkit.java

public static JFreeChart getPlot(double[] xData, double[] yData, String title, String xlabel, String ylabel) {

    XYSeriesCollection datCol = getCollection(xData, yData, "Data");

    // Create the chart

    JFreeChart chart = ChartFactory.createXYLineChart(title, // Title
            xlabel, // X-Axis label
            ylabel, // Y-Axis label
            new XYSeriesCollection(), // Dataset
            PlotOrientation.VERTICAL, true, // Show legend
            true, true);//w w  w. j a  va 2  s .  c  om

    // Add the series
    chart.getXYPlot().setDataset(0, datCol);

    // Set the rendering
    XYLineAndShapeRenderer rend1 = new XYLineAndShapeRenderer(true, true);
    rend1.setShapesVisible(false);
    chart.getXYPlot().setRenderer(0, rend1);

    return chart;
}

From source file:techtonic.PlotLogGraphListener.java

@Override
public void actionPerformed(ActionEvent e) {

    List<WitsmlLogCurve> curves = log.getCurves();

    Vector<String> curveDescription = new Vector<>();
    for (WitsmlLogCurve c : curves) {
        // System.out.println(c.getDescription());
        curveDescription.add(c.getDescription());
    }/*from w ww  .  j  a v  a 2 s  . c  o m*/
    Techtonic.setjcbX_Axis(curveDescription);

    Techtonic.setEnablejcbX_Axis(true);
    Techtonic.setEnablejcbY_Axis(false);
    Techtonic.setEnableRenderBtn(true);
    Techtonic.setPropertyBtn(true);

    //Techtonic.setjcbX_Axis();
    Vector<String> v = new Vector<String>(Arrays.asList(new String[] { "Depth" }));
    Techtonic.setjcbY_Axis(v);
    //plot the graph using values of the second entry
    WitsmlLogCurve ydata = curves.get(0);
    WitsmlLogCurve xdata = curves.get(1);
    List<Object> yvalues = ydata.getValues();
    List<Object> xvalues = xdata.getValues();
    String title = "Depth against " + xdata.getDescription();
    XYSeries series = new XYSeries(title);

    for (int i = 0; i < yvalues.size(); i++) {
        Object vx = xvalues.get(i);
        Object vy = yvalues.get(i);
        double dx = Double.parseDouble(vx.toString());
        double dy = Double.parseDouble(vy.toString());
        series.add(dx, dy);
    }
    XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(series);

    // create a chart using the createYLineChart method...
    JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title
            xdata.getDescription(), "Depth", // x and y axis labels
            data); // data

    ChartPanel cp = new ChartPanel(chart);
    //            JFrame fr = new JFrame();
    //            fr.add(cp);
    //            fr.pack();
    //            fr.setVisible(true);
    //cp.setMouseZoomable(true, true);  
    Techtonic.setFreeChart(chart);
    Techtonic.setCurrentCurves(curves);
    Techtonic.setDisplayArea(cp);
    //            chartPanel.setLayout(new java.awt.BorderLayout());
    //            chartPanel.add(cp,BorderLayout.CENTER);
    //            chartPanel.validate();
    //            chartPanel.repaint();
}

From source file:edu.turtlekit2.tools.chart.ChartWindow.java

/**
 * Add a new chart to the chart window. 
 * @param chartName - the name of the chart.
 * @param xName - the name of the x-axis.
 * @param yName - the name of the y-axis.
 *///from w  ww .  ja  v a 2s  . c o m
public void addChart(String chartName, String xName, String yName) {
    final XYSeriesCollection dataset = new XYSeriesCollection();
    sets.put(chartName, dataset);
    final JFreeChart chart = createChart(dataset, chartName, xName, yName);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(550, 250));
    add(chartPanel);
}