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:com.devoteam.srit.xmlloader.gui.frames.JFrameRunProfile.java

private void refreshGraph(int type) {
    ArrayList<Point> vector = runProfile.getPoints();
    this.jPanelGraph.removeAll();

    if (type == 1) // delay graph
    {//  www  .j  a v a  2 s . c  o  m
        XYSeries series = new XYSeries("Delay");
        for (Point point : vector)
            series.add(point.date / 1000, 1 / point.frequency);
        XYDataset xyDataset = new XYSeriesCollection(series);
        JFreeChart chart = ChartFactory.createXYLineChart(null, "date (s)", "delay (s)", xyDataset,
                PlotOrientation.VERTICAL, false, true, false);
        ChartPanel panel = new ChartPanel(chart);
        panel.setPreferredSize(jPanelGraph.getSize());
        this.jPanelGraph.add(panel);
        this.jPanelGraph.validate();
    } else // frequency graph
    {
        XYSeries series = new XYSeries("Frequency");
        for (Point point : vector)
            series.add(point.date / 1000, point.frequency);
        XYDataset xyDataset = new XYSeriesCollection(series);
        JFreeChart chart = ChartFactory.createXYLineChart(null, "date (s)", "frequency (hz)", xyDataset,
                PlotOrientation.VERTICAL, false, true, false);
        chart.setPadding(new RectangleInsets(0, 0, 0, 0));
        ChartPanel panel = new ChartPanel(chart);
        panel.setPreferredSize(jPanelGraph.getSize());
        this.jPanelGraph.add(panel);
        this.jPanelGraph.validate();
    }
}

From source file:ch.epfl.leb.sass.ijplugin.SimulatorStatusFrame.java

/** 
 * Creates a new status frame.//from  ww w  .ja va2 s . c  om
 * 
 * @param groundTruthYLabel The y-axis label for the ground truth signal.
 * @param analyzerYLabel The units output by the analyzer.
 * @param setpointYLabel The units of the controller setpoint.
 * @param outputYLabel The units output by the controller.
 */
public SimulatorStatusFrame(String groundTruthYLabel, String analyzerYLabel, String setpointYLabel,
        String outputYLabel) {
    String seriesLabel = "";
    String yLabel = "";
    CombinedDomainXYPlot combineddomainxyplot = new CombinedDomainXYPlot(new NumberAxis("Simulation Outputs"));
    Font yLabelFont = new Font("Dialog", Font.PLAIN, 10);
    datasets = new XYSeriesCollection[4];
    for (int i = 0; i < SUBPLOT_COUNT; i++) {
        switch (i) {
        case 0:
            seriesLabel = "True density";
            yLabel = groundTruthYLabel;
            break;
        case 1:
            seriesLabel = "Analyzer output";
            yLabel = analyzerYLabel;
            break;
        case 2:
            seriesLabel = "Setpoint";
            yLabel = setpointYLabel;
            break;
        case 3:
            seriesLabel = "Controller output";
            yLabel = outputYLabel;
            break;
        }

        XYSeries timeseries = new XYSeries(seriesLabel);
        datasets[i] = new XYSeriesCollection(timeseries);

        NumberAxis numberaxis = new NumberAxis(yLabel);
        numberaxis.setAutoRangeIncludesZero(false);
        numberaxis.setNumberFormatOverride(new DecimalFormat("###0.00"));
        XYPlot xyplot = new XYPlot(datasets[i], null, numberaxis, new StandardXYItemRenderer());
        xyplot.setBackgroundPaint(Color.lightGray);
        xyplot.setDomainGridlinePaint(Color.white);
        xyplot.setRangeGridlinePaint(Color.white);
        xyplot.getRangeAxis().setLabelFont(yLabelFont);
        combineddomainxyplot.add(xyplot);
    }

    JFreeChart jfreechart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, combineddomainxyplot, true);
    jfreechart.setBorderPaint(Color.black);
    jfreechart.setBorderVisible(true);
    jfreechart.setBackgroundPaint(Color.white);
    combineddomainxyplot.setBackgroundPaint(Color.lightGray);
    combineddomainxyplot.setDomainGridlinePaint(Color.white);
    combineddomainxyplot.setRangeGridlinePaint(Color.white);
    ValueAxis valueaxis = combineddomainxyplot.getDomainAxis();
    valueaxis.setAutoRange(true);
    // Number of frames to display
    valueaxis.setFixedAutoRange(2000D);

    ChartPanel chartpanel = new ChartPanel(jfreechart);

    chartpanel.setPreferredSize(new Dimension(800, 500));
    chartpanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    chartpanel.setVisible(true);

    JPanel jPanel = new JPanel();
    jPanel.setLayout(new BorderLayout());
    jPanel.add(chartpanel, BorderLayout.NORTH);

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    add(jPanel);
    pack();
    setVisible(true);

}

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

@Override
public void populate(XYPlot plot, AROTraceData analysis) {
    XYSeries series = new XYSeries(0);
    if (analysis == null) {
        logger.info("analysis data is null");
    } else {/*from  w  w w  . j  a v  a2  s .c o  m*/
        TraceResultType resultType = analysis.getAnalyzerResult().getTraceresult().getTraceResultType();
        if (resultType.equals(TraceResultType.TRACE_FILE)) {
            logger.info("didn't get analysis trace data!");
        } else {
            TraceDirectoryResult traceresult = (TraceDirectoryResult) analysis.getAnalyzerResult()
                    .getTraceresult();
            AnalysisFilter filter = analysis.getAnalyzerResult().getFilter();
            temperatureInfos = traceresult.getTemperatureInfos();

            if (temperatureInfos.size() > 0) {
                for (TemperatureEvent bi : temperatureInfos) {
                    series.add(bi.getTimeRecorded(), bi.getcelciusTemperature());
                }

                TemperatureEvent last = temperatureInfos.get(temperatureInfos.size() - 1);
                if (filter.getTimeRange() != null) {
                    series.add(filter.getTimeRange().getEndTime(), last.getcelciusTemperature());
                } else {
                    series.add(traceresult.getTraceDuration(), last.getcelciusTemperature());
                }
            }

            XYItemRenderer renderer = plot.getRenderer();
            renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
                @Override
                public String generateToolTip(XYDataset dataset, int series, int item) {
                    return toolTipContent(item);
                }
            });
        }
        plot.setDataset(new XYSeriesCollection(series));
    }
}

From source file:org.interpss.chart.dstab.SimpleOneStateChart.java

/**
 * create a XYDataSet object/*from w ww.  jav  a 2  s  .  com*/
 * 
 * @param xData x-axis data points
 * @param yData y-axis data points
 * @param label y-axis data label
 * @return
 */
public static XYDataset createXYDataSet(final double[] xData, final double[] yData, final String label) {
    final XYSeries series = new XYSeries(label);
    for (int i = 0; i < xData.length; i++) {
        series.add(xData[i], yData[i]);
    }
    return new XYSeriesCollection(series);
}

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

public XyGui(String title, double[] x) {

    super(title);

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

    if (checkX(x)) {

        XYSeries xydata = new XYSeries(title);

        for (int i = 0; i < loopInt; i++) {
            xydata.add(x[i], C.ZERO_DOUBLE);
        }

        xycollection = new XYSeriesCollection(xydata);

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

        final XYPlot plot = chart.getXYPlot();

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

        final NumberAxis rangeAxis = new NumberAxis("y");
        plot.setRangeAxis(rangeAxis);

        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:edu.umich.eecs.tac.viewer.role.advertiser.CampaignGrpahsPanel.java

private void createGraph(XYSeries reachSeries) {
    XYSeriesCollection seriescollection = new XYSeriesCollection(reachSeries);

    maxSeries = new XYSeries("Total");
    for (int i = 1; i <= 1000; i++) {
        double err = calcEffectiveReachRatio(expectedImpressionReach * i / 1000, expectedImpressionReach);
        maxSeries.add(expectedImpressionReach * i / 1000, err);
    }/*from w  w w . ja v  a 2s . c  o m*/

    seriescollection.addSeries(maxSeries);
    JFreeChart chart = createDifferenceChart(advertiserBorder ? null : advertiser, seriescollection,
            "Reach Count", "Reach percentage");
    ChartPanel chartpanel = new ChartPanel(chart, false);
    chartpanel.setMouseZoomable(true, false);
    add(chartpanel);
    this.repaint();
}

From source file:PointingMap.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {

    Connection conn = null;/*from  w w w.j  a va2  s  .  c om*/
    Statement stmt = null;
    ResultSet rs = null;
    ResultSetMetaData rsm = null;

    OutputStream out = response.getOutputStream();
    try {

        String dbHost = request.getParameter("dbHost");
        String dbName = request.getParameter("dbName");

        conn = connect(dbHost, dbName);

        // get & plot target catalog
        String targetCatQuery = "select " + "ra2000Hours, dec2000Deg " + "from TargetCat limit 200";

        stmt = conn.createStatement();
        rs = stmt.executeQuery(targetCatQuery);
        rsm = rs.getMetaData();
        //int colCount = rsm.getColumnCount();

        XYSeries series = new XYSeries("Target Catalog");
        int raColIndex = 1;
        int decColIndex = 2;
        while (rs.next()) {
            series.add(rs.getDouble(raColIndex), rs.getDouble(decColIndex));
        }

        XYDataset data = new XYSeriesCollection(series);
        stmt.close();

        // Get latest primary beam pointing position
        String latestPointingQuery = "select " + "actId, ts, " + "raHours, decDeg " + "from TscopePointReq "
                + "where atabeam = 'primary' " + "order by actId desc limit 1";

        stmt = conn.createStatement();
        rs = stmt.executeQuery(latestPointingQuery);
        rsm = rs.getMetaData();
        //int colCount = rsm.getColumnCount();

        int actId = -1;
        String timeString = "";
        double pointingRaHours = -1;
        double pointingDecDeg = -1;

        int actIdIndex = 1;
        int timeIndex = 2;
        raColIndex = 3;
        decColIndex = 4;

        while (rs.next()) {
            actId = rs.getInt(actIdIndex);
            timeString = rs.getString(timeIndex);
            pointingRaHours = rs.getDouble(raColIndex);
            pointingDecDeg = rs.getDouble(decColIndex);
        }

        String plotTitle = "ATA Primary Pointing" + " (Act Id: " + actId + ")" + " " + timeString;

        JFreeChart chart = ChartFactory.createScatterPlot(plotTitle, "RA (Hours)", // x-axis label
                "Dec (Deg)", // y axis label
                data, PlotOrientation.VERTICAL, false, // legend 
                true, // tooltips
                false // urls
        );

        // plot RA hours with higher values to the left
        //chart.getXYPlot().getDomainAxis().setInverted(true);
        chart.getXYPlot().getDomainAxis().setLowerBound(-1);
        chart.getXYPlot().getDomainAxis().setUpperBound(25);

        // increase axis label fonts for better readability
        Font axisFont = new Font("Serif", Font.BOLD, 14);
        chart.getXYPlot().getDomainAxis().setLabelFont(axisFont);
        chart.getXYPlot().getDomainAxis().setTickLabelFont(axisFont);
        chart.getXYPlot().getRangeAxis().setLabelFont(axisFont);
        chart.getXYPlot().getRangeAxis().setTickLabelFont(axisFont);

        // show current pointing as crosshairs
        chart.getXYPlot().setDomainCrosshairValue(pointingRaHours);
        chart.getXYPlot().setRangeCrosshairValue(pointingDecDeg);
        chart.getXYPlot().setDomainCrosshairVisible(true);
        chart.getXYPlot().setRangeCrosshairVisible(true);
        chart.getXYPlot().setDomainCrosshairPaint(Color.BLACK);
        chart.getXYPlot().setRangeCrosshairPaint(Color.BLACK);

        Stroke stroke = new BasicStroke(2);
        chart.getXYPlot().setDomainCrosshairStroke(stroke);
        chart.getXYPlot().setRangeCrosshairStroke(stroke);

        // set hat creek dec range
        chart.getXYPlot().getRangeAxis().setLowerBound(-40);
        chart.getXYPlot().getRangeAxis().setUpperBound(90);

        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();
        int seriesIndex = 0;
        renderer.setSeriesPaint(seriesIndex, Color.BLUE);

        Shape circularShape = new Ellipse2D.Double(-1.0, -1.0, 1.2, 1.2);
        renderer.setSeriesShape(seriesIndex, circularShape);

        // Default shape [0-9]: 0=square 1=circle 2=uptriangle 3=diamond...
        //renderer.setShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[1]);
        response.setContentType("image/png");
        int width = 800;
        int height = 600;
        ChartUtilities.writeChartAsPNG(out, chart, width, height);

    } catch (Exception e) {
        throw new ServletException(e);
    } finally {

        try {
            if (stmt != null) {
                stmt.close();
            }

            if (conn != null) {
                conn.close();
            }

        } catch (SQLException sql) {
        }

    }

}

From source file:opensonata.dataDisplays.BaselineImage.java

private JFreeChart createChart(String inFilename, String userTitle, 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]);
    }//w w w  .  ja v  a2 s  . co m

    System.err.println("HERE!!!!");

    // add a final point at the end with a zero Y value,
    series.add(baselineValues.length, 0.0);

    XYDataset data = new XYSeriesCollection(series);

    String inFilenameBase = new File(inFilename).getName();

    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 mainTitle = "";
    String xAxisLabel = "Subband";
    String yAxisLabel = "Power";

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

    String subTitle1 = "Baseline: ";
    if (!userTitle.equals("")) {
        subTitle1 += userTitle;
    } else {
        subTitle1 += inFilenameBase;
    }
    chart.addSubtitle(new TextTitle(subTitle1));

    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:imageprocessingproject.ImageHistogram.java

public static JFreeChart plotHistogram(BufferedImage image) {
    createHistogram(image);//from   w  w w .  ja  v  a2  s . c  om

    final XYSeries series = new XYSeries("Histogram Data");

    for (int i = 0; i < histogram.length; i++) {
        series.add(i, histogram[i]);
    }

    final XYSeriesCollection data = new XYSeriesCollection(series);
    final JFreeChart chart = ChartFactory.createXYLineChart("Image Histogram", "intensity", "PDF", data,
            PlotOrientation.VERTICAL, true, true, false);

    return chart;
}

From source file:com.wattzap.view.Profile.java

@Override
public void callback(Messages message, Object o) {
    double distance = 0.0;
    switch (message) {
    case SPEED://from w ww.j  av  a  2s  .  c  o m
        Telemetry t = (Telemetry) o;
        distance = t.getDistanceKM();
        break;
    case STARTPOS:
        distance = (Double) o;
        break;
    case CLOSE:
        if (this.isVisible()) {
            remove(chartPanel);
            setVisible(false);
            revalidate();
        }

        return;
    case GPXLOAD:
        // Note if we are loading a Power Profile there is no GPX data so we don't show the chart panel
        RouteReader routeData = (RouteReader) o;

        if (chartPanel != null) {
            remove(chartPanel);
            if (routeData.routeType() == RouteReader.POWER) {
                setVisible(false);
                chartPanel.revalidate();
                return;
            }
        } else if (routeData.routeType() == RouteReader.POWER) {
            return;
        }

        logger.debug("Load " + routeData.getFilename());
        XYDataset xyDataset = new XYSeriesCollection(routeData.getSeries());

        // create the chart...
        final JFreeChart chart = ChartFactory.createXYAreaChart(routeData.getName(), // chart
                // title
                userPrefs.messages.getString("distancekm"), // domain axis label
                userPrefs.messages.getString("heightMeters"), // range axis label
                xyDataset, // data
                PlotOrientation.VERTICAL, // orientation
                false, // include legend
                false, // tooltips
                false // urls
        );

        chart.setBackgroundPaint(Color.darkGray);

        plot = chart.getXYPlot();
        // plot.setForegroundAlpha(0.85f);

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

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

        double minY = routeData.getSeries().getMinY();
        double maxY = routeData.getSeries().getMaxY();
        rangeAxis.setRange(minY - 100.0, maxY + 100.0);

        chartPanel = new ChartPanel(chart);

        chartPanel.setSize(100, 800);

        setLayout(new BorderLayout());
        add(chartPanel, BorderLayout.CENTER);
        setBackground(Color.black);
        chartPanel.revalidate();
        setVisible(true);
        break;
    }// switch
    if (plot == null) {
        return;
    }

    if (marker != null) {
        plot.removeDomainMarker(marker);
    }
    marker = new ValueMarker(distance);

    marker.setPaint(Color.blue);
    BasicStroke stroke = new BasicStroke(2);
    marker.setStroke(stroke);
    plot.addDomainMarker(marker);

}