Example usage for org.jfree.chart JFreeChart getXYPlot

List of usage examples for org.jfree.chart JFreeChart getXYPlot

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart getXYPlot.

Prototype

public XYPlot getXYPlot() 

Source Link

Document

Returns the plot cast as an XYPlot .

Usage

From source file:fungus.PeerRatioChartFrame.java

public PeerRatioChartFrame(String prefix) {
    simulationCycles = Configuration.getDouble(PAR_SIMULATION_CYCLES);
    this.setTitle("MycoNet Statistics Chart");
    graph = JungGraphObserver.getGraph();

    //data.add(-1,0);
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.setAutoWidth(false);/*from www. ja  v a2  s .  c  om*/
    dataset.setIntervalWidth(simulationCycles);

    //averageUtilizationData = new XYSeries("Average Utilization");
    //dataset.addSeries(averageUtilizationData);
    //averageStableUtilizationData = new XYSeries("Avg Stable Util");
    //dataset.addSeries(averageStableUtilizationData);
    bulwarkRatioData = new XYSeries("Bulwark Ratio");
    dataset.addSeries(bulwarkRatioData);
    biomassRatioData = new XYSeries("Biomass Ratio");
    dataset.addSeries(biomassRatioData);
    hyphaRatioData = new XYSeries("Hypha Ratio");
    dataset.addSeries(hyphaRatioData);
    // stableHyphaRatioData = new XYSeries("Stable Hypha Ratio");
    // dataset.addSeries(stableHyphaRatioData);

    //XYSeriesCollection dataset;

    JFreeChart peerRatioChart = ChartFactory.createXYLineChart("Bulwark Metrics", "Cycle", "Peer State Ratio",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    ChartPanel peerRatioChartPanel = new ChartPanel(peerRatioChart);

    XYPlot xyplot = peerRatioChart.getXYPlot();

    NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis();
    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setRange(0, 1);

    //chart.setBackgroundPaint(Color.white);
    //XYPlot plot = chart.getXYPlot();

    //        BufferedImage chartImage = chart.createBufferedImage(500,300);
    //        chartLabel = new JLabel();
    //chartLabel.setIcon(new ImageIcon(chartImage));

    Container contentPane = getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
    JPanel labelPane = new JPanel();
    labelPane.setLayout(new GridLayout(1, 1));
    //chartPane.setPreferredSize(new java.awt.Dimension(500, 300));
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));

    ////contentPane.add(labelPane,BorderLayout.PAGE_START);
    //contentPane.add(Box.createRigidArea(new Dimension(0,5)));
    contentPane.add(peerRatioChartPanel, BorderLayout.CENTER);
    //contentPane.add(Box.createRigidArea(new Dimension(0,5)));
    ////contentPane.add(buttonPane, BorderLayout.PAGE_END);

    //data = node.getHyphaData();
    //link = node.getHyphaLink();
    //mycocast = node.getMycoCast();

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    //chartPanel.add(chartLabel);

    /*JButton updateButton = new JButton("Refresh");
      ActionListener updater = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      refreshData();
      }
      };
      updateButton.addActionListener(updater);
            
      JButton closeButton = new JButton("Close");
      ActionListener closer = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      closeFrame();
      }
      };
      closeButton.addActionListener(closer);
            
      buttonPane.add(Box.createHorizontalGlue());
      buttonPane.add(updateButton);
      buttonPane.add(Box.createRigidArea(new Dimension(5,0)));
      buttonPane.add(closeButton);
      refreshData();
    */

    //JungGraphObserver.addChangeListener(this);

    this.pack();
    this.setVisible(true);
}

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

/**
 * Creates a chart./*  ww w.j  av a  2  s. co  m*/
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", "Date",
            "Price Per Unit", dataset, true, true, false);

    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend sl = (StandardLegend) chart.getLegend();
    //        sl.setDisplaySeriesShapes(true);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    final XYItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        rr.setPlotShapes(true);
        rr.setShapesFilled(true);
        rr.setItemLabelsVisible(true);
    }

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    return chart;

}

From source file:com.bitplan.vzjava.Plot.java

/**
 * Creates a chart./*from  ww  w  .  j av  a2 s  .co m*/
 * 
 * @param dataset
 *          a dataset.
 * 
 * @return A chart.
 */
private JFreeChart createChart(final ColoredDataSet cdataset) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, "Time", "Power", cdataset.dataSet, true,
            true, false);

    chart.setBackgroundPaint(Color.white);

    // final StandardLegend sl = (StandardLegend) chart.getLegend();
    // sl.setDisplaySeriesShapes(true);

    final XYPlot plot = chart.getXYPlot();
    // plot.setOutlinePaint(null);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(false);

    final XYItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof StandardXYItemRenderer) {
        renderer.setSeriesStroke(0, new BasicStroke(3.0f));
        renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    }

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));

    // http://www.jfree.org/jfreechart/api/gjdoc/org/jfree/chart/plot/DefaultDrawingSupplier-source.html
    DrawingSupplier supplier = new DefaultDrawingSupplier(cdataset.paintSequence,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
    chart.getPlot().setDrawingSupplier(supplier);
    return chart;
}

From source file:playground.johannes.snowball.Histogram.java

public void plot(String filename, String title) throws IOException {
    fillBins();/*from   w  w  w  .  ja  va  2  s. com*/
    final XYSeriesCollection data = new XYSeriesCollection();
    final XYSeries wave = new XYSeries(title, false, true);

    double min, max, width;
    //      int size;

    if (bounds != null) {
        min = bounds[0];
        max = bounds[1];
    } else {
        double minmax[] = getMinMax();
        min = minmax[0];
        max = minmax[1];
    }
    if (binWidth > 0) {
        //         size = (int)Math.ceil((max - min)/(double)binWidth);
        width = binWidth;
    } else {
        //         size = bincount;
        width = (max - min) / (double) bincount;
    }

    int cnt = bins.size();
    for (int i = 0; i < cnt; i++) {
        wave.add(i * width + min, bins.get(i));
    }

    data.addSeries(wave);

    final JFreeChart chart = ChartFactory.createXYStepChart("title", "x", "y", data, PlotOrientation.VERTICAL,
            true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("x");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("y"));
    ChartUtilities.saveChartAsPNG(new File(filename), chart, 1024, 768);
}

From source file:playground.christoph.icem2011.LogLinkTravelTime.java

private void createChart(Link link, String file) {

    //      String s = data.get(linkId).toString();
    //      String[] travelTimes = s.split("\n");
    List<Double> etts = data.get(link.getId());

    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries expectedTravelTimes = new XYSeries("expected travel times", false, true);
    final XYSeries measuredTravelTimes = new XYSeries("measured travel times", false, true);
    for (int i = 0; i < times.size(); i++) {
        double time = times.get(i);
        if (time > graphCutOffTime)
            break; // do not display values > 30h in the graph
        double hour = Double.valueOf(time) / 3600.0;
        expectedTravelTimes.add(hour, Double.valueOf(etts.get(i)));
        measuredTravelTimes.add(hour,/*from w  w  w  . j a  v a 2s .com*/
                Double.valueOf(measuredTravelTime.getLinkTravelTime(link, time, null, null)));
    }

    xyData.addSeries(expectedTravelTimes);
    xyData.addSeries(measuredTravelTimes);

    //      final JFreeChart chart = ChartFactory.createXYStepChart(
    final JFreeChart chart = ChartFactory.createXYLineChart(
            "Compare expected and measured travel times for link " + link.getId().toString(), "time",
            "travel time", xyData, PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));

    try {
        ChartUtilities.saveChartAsPNG(new File(file), chart, 1024, 768);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.seniorproject.augmentedreality.chart.ChartCreator.java

private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart1 = ChartFactory.createXYLineChart(this.title[0], // chart title
            "Intensity", // x axis label
            "number of pixel", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*w  w  w  .  j av  a 2 s .c om*/

    chart1.setBackgroundPaint(Color.white);
    final XYPlot plot = chart1.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    //        final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    //        renderer.setSeriesLinesVisible(5, true);
    //        renderer.setSeriesShapesVisible(1, false);
    //        plot.setRenderer(renderer);
    //        final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    //        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return chart1;
}

From source file:org.yccheok.jstock.gui.charting.DynamicChart.java

/** Creates new form DynamicChart */
public DynamicChart() {
    this.price = new TimeSeries("Price");
    // Sets the maximumItemAge attribute, which specifies the maximum age of data items in the series
    // (in terms of the RegularTimePeriod type used by this series). Whenever a new data value is
    // added, any data items that are older than the limit specified by maximumItemAge are automatically
    // discarded//from  w ww  .j  a v  a  2 s .  c o m
    // Maximum 2 hours.
    this.price.setMaximumItemAge(2 * 60 * 60);

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(this.price);

    JFreeChart freeChart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, true, false);

    freeChart.setAntiAlias(true);
    while (freeChart.getSubtitleCount() > 0) {
        freeChart.removeSubtitle(freeChart.getSubtitle(0));
    }

    // Due to limited spacing, we remove all information regarding x and y axis
    // as well.
    XYPlot plot = freeChart.getXYPlot();
    plot.getRangeAxis().setVisible(false);
    plot.getDomainAxis().setVisible(false);

    XYItemRenderer renderer1 = plot.getRenderer();
    renderer1.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("h:mm:ss a"), new DecimalFormat("0.00#")));

    org.yccheok.jstock.charting.Utils.applyChartTheme(freeChart);

    // Disable zoom.
    chartPanel = new ChartPanel(freeChart, true, true, true, false, true);
    chartPanel.setMouseZoomable(false);
}

From source file:udpserver.UDPui.java

/**
 * Creates new form UDPui/*from  ww  w .  j  a v  a 2  s.  c om*/
 */
public UDPui() {
    // <editor-fold defaultstate="collapsed" desc="Graph">
    series = new XYSeries("ECG Reading");
    series.setMaximumItemCount(50);
    XYSeriesCollection dataset = new XYSeriesCollection(series);
    JFreeChart chart = ChartFactory.createXYLineChart("ECG Reading", "Time (seconds)", "Voltage (volt)",
            dataset);

    final XYPlot plot = chart.getXYPlot();
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();

    JPanel jPanel1 = new JPanel();
    jPanel1.setLayout(new java.awt.BorderLayout());
    jPanel1.setVisible(true);
    jPanel1.setSize(600, 500);
    jPanel1.add(new ChartPanel(chart), BorderLayout.CENTER);
    jPanel1.validate();
    add(jPanel1);
    // </editor-fold>
    initComponents();
    receiveUDP();
    //        tempReceiveUDP();
    //        new UDPServer(valuePane);
}

From source file:gui.DendrogramChart.java

ChartPanel getChartPanel(Dendrogram d, boolean log) {
    JFreeChart chart = ChartFactory.createXYLineChart(null, "Similarity", "No. of Groups", null,
            PlotOrientation.VERTICAL, true, true, false);

    setChartData(chart, log);/*  w ww .jav a 2s  . com*/

    RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    chart.setRenderingHints(rh);
    chart.removeLegend();

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(new Color(255, 255, 220));
    plot.setDomainGridlinePaint(new Color(128, 128, 128));
    plot.setRangeGridlinePaint(new Color(128, 128, 128));
    if (log == false) {
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        rangeAxis.setLowerBound(0);
        rangeAxis.setNumberFormatOverride(new DecimalFormat("0"));
        rangeAxis.setLabelFont(Prefs.labelFont);
    } else {
        // LogarithmicAxis logXAxis = new LogarithmicAxis("Similarity");
        // logXAxis.setAllowNegativesFlag(true);
        LogarithmicAxis logYAxis = new LogarithmicAxis("No. Of Groups");
        logYAxis.setAllowNegativesFlag(false);

        // plot.setDomainAxis(logXAxis);
        plot.setRangeAxis(logYAxis);
    }

    ChartPanel chartPanel = new ChartPanel(chart);
    // chartPanel.setPopupMenu(null);
    return chartPanel;
}

From source file:org.yccheok.jstock.gui.SellPortfolioTimeChartJDialog.java

private JFreeChart createChart(String name) {
    final JStockOptions jStockOptions = MainFrame.getInstance().getJStockOptions();
    final boolean isFeeCalculationEnabled = jStockOptions.isFeeCalculationEnabled();
    final boolean isPenceToPoundConversionEnabled = jStockOptions.isPenceToPoundConversionEnabled();

    final Portfolio portfolio = (Portfolio) portfolioTreeTableModel.getRoot();
    final int count = portfolio.getChildCount();

    final List<DataEx> dataExs = new ArrayList<DataEx>();

    for (int i = 0; i < count; i++) {
        TransactionSummary transactionSummary = (TransactionSummary) portfolio.getChildAt(i);

        if (transactionSummary.getChildCount() <= 0) {
            continue;
        }/*from w  w  w  .  java 2s.co m*/

        Transaction transaction = (Transaction) transactionSummary.getChildAt(0);
        final Date date = transaction.getDate().getTime();

        if (name.equals(cNames[2]) || name.equals(cNames[3])) {
            this.isCumulativeChart = true;
        } else {
            this.isCumulativeChart = false;
        }

        /* Should use reflection technology. */
        if (name.equals(cNames[0]) || name.equals(cNames[2])) {
            if (isPenceToPoundConversionEnabled == false) {
                if (isFeeCalculationEnabled) {
                    dataExs.add(DataEx.newInstance(date,
                            portfolioTreeTableModel.getNetGainLossValue(transactionSummary)));
                } else {
                    dataExs.add(DataEx.newInstance(date,
                            portfolioTreeTableModel.getGainLossValue(transactionSummary)));
                }
            } else {
                if (isFeeCalculationEnabled) {
                    dataExs.add(DataEx.newInstance(date,
                            portfolioTreeTableModel.getNetGainLossValue(transactionSummary) / 100.0));
                } else {
                    dataExs.add(DataEx.newInstance(date,
                            portfolioTreeTableModel.getGainLossValue(transactionSummary) / 100.0));
                }
            }
        } else if (name.equals(cNames[1]) || name.equals(cNames[3])) {
            if (isPenceToPoundConversionEnabled == false) {
                if (isFeeCalculationEnabled) {
                    dataExs.add(DataEx.newInstance(date,
                            -portfolioTreeTableModel.getNetGainLossValue(transactionSummary)));
                } else {
                    dataExs.add(DataEx.newInstance(date,
                            -portfolioTreeTableModel.getGainLossValue(transactionSummary)));
                }
            } else {
                if (isFeeCalculationEnabled) {
                    dataExs.add(DataEx.newInstance(date,
                            -portfolioTreeTableModel.getNetGainLossValue(transactionSummary) / 100.0));
                } else {
                    dataExs.add(DataEx.newInstance(date,
                            -portfolioTreeTableModel.getGainLossValue(transactionSummary) / 100.0));
                }
            }
        }
    }

    Collections.sort(dataExs);
    TimeSeries series = new TimeSeries(name);
    double totalValue = 0;
    for (DataEx dataEx : dataExs) {
        double value = dataEx.value;
        if (!this.isCumulativeChart && series.getValue(new Day(dataEx.date)) != null) {
            value += series.getValue(new Day(dataEx.date)).doubleValue();
        }

        if (this.isCumulativeChart) {
            totalValue += value;
            series.addOrUpdate(new Day(dataEx.date), totalValue);
        } else {
            series.addOrUpdate(new Day(dataEx.date), value);
        }

    }

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(name, "date", null, dataset, false, true, false);

    ValueMarker marker = new ValueMarker(0);
    marker.setPaint(Color.black);

    XYPlot plot = (XYPlot) chart.getXYPlot();
    plot.addRangeMarker(marker);

    return chart;

}