Example usage for org.jfree.chart.plot XYPlot setDataset

List of usage examples for org.jfree.chart.plot XYPlot setDataset

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot setDataset.

Prototype

public void setDataset(int index, XYDataset dataset) 

Source Link

Document

Sets a dataset for the plot and sends a change event to all registered listeners.

Usage

From source file:ta4jexamples.indicators.CandlestickChart.java

public static void main(String[] args) {
    /**/*from ww  w . jav a2  s  .  c  o m*/
     * Getting time series
     */
    TimeSeries series = CsvTradesLoader.loadBitstampSeries();

    /**
     * Creating the OHLC dataset
     */
    OHLCDataset ohlcDataset = createOHLCDataset(series);

    /**
     * Creating the additional dataset
     */
    TimeSeriesCollection xyDataset = createAdditionalDataset(series);

    /**
     * Creating the chart
     */
    JFreeChart chart = ChartFactory.createCandlestickChart("Bitstamp BTC price", "Time", "USD", ohlcDataset,
            true);
    // Candlestick rendering
    CandlestickRenderer renderer = new CandlestickRenderer();
    renderer.setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST);
    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(renderer);
    // Additional dataset
    int index = 1;
    plot.setDataset(index, xyDataset);
    plot.mapDatasetToRangeAxis(index, 0);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
    renderer2.setSeriesPaint(index, Color.blue);
    plot.setRenderer(index, renderer2);
    // Misc
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setBackgroundPaint(Color.white);
    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    numberAxis.setAutoRangeIncludesZero(false);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    /**
     * Displaying the chart
     */
    displayChart(chart);
}

From source file:de.bund.bfr.knime.chart.ChartUtils.java

public static void addDataSetToPlot(XYPlot plot, XYDataset dataSet, XYItemRenderer renderer) {
    int i = plot.getDataset(0) == null ? 0 : plot.getDatasetCount();

    plot.setDataset(i, dataSet);
    plot.setRenderer(i, renderer);//from  w ww  .  j a va2 s .  co m
}

From source file:com.spotify.heroic.http.render.RenderUtils.java

private static JFreeChart buildChart(final String title, final XYDataset lineAndShape, final XYDataset interval,
        final XYItemRenderer lineAndShapeRenderer, final XYItemRenderer intervalRenderer) {
    final ValueAxis timeAxis = new DateAxis();
    timeAxis.setLowerMargin(0.02);//w  w w  .j  a v a 2  s  . co  m
    timeAxis.setUpperMargin(0.02);

    final NumberAxis valueAxis = new NumberAxis();
    valueAxis.setAutoRangeIncludesZero(false);

    final XYPlot plot = new XYPlot();

    plot.setDomainAxis(0, timeAxis);
    plot.setRangeAxis(0, valueAxis);

    plot.setDataset(0, lineAndShape);
    plot.setRenderer(0, lineAndShapeRenderer);

    plot.setDomainAxis(1, timeAxis);
    plot.setRangeAxis(1, valueAxis);

    plot.setDataset(1, interval);
    plot.setRenderer(1, intervalRenderer);

    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
}

From source file:ta4jexamples.analysis.CashFlowToChart.java

/**
 * Adds the cash flow axis to the plot.//from  w w w .j  a  va2  s  . c  o m
 * @param plot the plot
 * @param dataset the cash flow dataset
 */
private static void addCashFlowAxis(XYPlot plot, TimeSeriesCollection dataset) {
    final NumberAxis cashAxis = new NumberAxis("Cash Flow Ratio");
    cashAxis.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(1, cashAxis);
    plot.setDataset(1, dataset);
    plot.mapDatasetToRangeAxis(1, 1);
    final StandardXYItemRenderer cashFlowRenderer = new StandardXYItemRenderer();
    cashFlowRenderer.setSeriesPaint(0, Color.blue);
    plot.setRenderer(1, cashFlowRenderer);
}

From source file:com.leonarduk.finance.chart.CandlestickChart.java

public static void displayCandlestickChart(final Stock stock) throws IOException {
    final TimeSeries series = TimeseriesUtils.getTimeSeries(stock, 1);

    /**/*w w w. j a  v  a2 s.  c  o  m*/
     * Creating the OHLC dataset
     */
    final OHLCDataset ohlcDataset = CandlestickChart.createOHLCDataset(series);

    /**
     * Creating the additional dataset
     */
    final TimeSeriesCollection xyDataset = CandlestickChart.createAdditionalDataset(series);

    /**
     * Creating the chart
     */
    final JFreeChart chart = ChartFactory.createCandlestickChart(stock.getName() + " price", "Time",
            stock.getCurrency(), ohlcDataset, true);
    // Candlestick rendering
    final CandlestickRenderer renderer = new CandlestickRenderer();
    renderer.setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST);
    final XYPlot plot = chart.getXYPlot();
    plot.setRenderer(renderer);
    // Additional dataset
    final int index = 1;
    plot.setDataset(index, xyDataset);
    plot.mapDatasetToRangeAxis(index, 0);
    final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
    renderer2.setSeriesPaint(index, Color.blue);
    plot.setRenderer(index, renderer2);
    // Misc
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setBackgroundPaint(Color.white);
    final NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    numberAxis.setAutoRangeIncludesZero(false);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    /**
     * Displaying the chart
     */
    ChartDisplay.displayChartInFrame(chart, 740, 300, "Candlestick Chart");
}

From source file:audio.cords.old.RegressionDemo.java

private static JFreeChart createChart(XYSeriesCollection data) {
    JFreeChart chart = ChartFactory.createScatterPlot(null, "X", "Y", data, PlotOrientation.VERTICAL, true,
            false, false);/*from w ww. jav a 2  s.  co  m*/
    XYPlot plot = (XYPlot) chart.getPlot();
    XYItemRenderer scatterRenderer = plot.getRenderer();
    StandardXYItemRenderer regressionRenderer = new StandardXYItemRenderer();
    regressionRenderer.setBaseSeriesVisibleInLegend(false);
    plot.setDataset(1, regress(data));
    plot.setRenderer(1, regressionRenderer);
    DrawingSupplier ds = plot.getDrawingSupplier();
    for (int i = 0; i < data.getSeriesCount(); i++) {
        Paint paint = ds.getNextPaint();
        scatterRenderer.setSeriesPaint(i, paint);
        regressionRenderer.setSeriesPaint(i, paint);
    }
    return chart;
}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.dec.TwoCoefsDecorator.java

/**
 * Clears the dataset containing the data used to visualizes the fitted function.
 * <p>// ww  w.j av  a  2 s .  co m
 * If the chart does not contain a decorating dataset, calling this method has no effect.
 * </p>
 * 
 * @param aChart Chart to be cleared from the decorating dataset.
 * @param aSeriesName Name of data series to be used for locating the decorating dataset.
 */
protected static void clearDataset(JFreeChart aChart, String aSeriesName) {
    XYPlot plot = aChart.getXYPlot();
    final int i = getDatasetIndex(plot, aSeriesName);
    if (i != -1) {
        plot.setDataset(i, new XYSeriesCollection(new XYSeries(aSeriesName)));
    }
}

From source file:com.leonarduk.finance.analysis.CashFlowToChart.java

/**
 * Adds the cash flow axis to the plot./*from  w w  w. java  2  s.co  m*/
 *
 * @param plot
 *            the plot
 * @param dataset
 *            the cash flow dataset
 */
private static void addCashFlowAxis(final XYPlot plot, final TimeSeriesCollection dataset) {
    final NumberAxis cashAxis = new NumberAxis("Cash Flow Ratio");
    cashAxis.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(1, cashAxis);
    plot.setDataset(1, dataset);
    plot.mapDatasetToRangeAxis(1, 1);
    final StandardXYItemRenderer cashFlowRenderer = new StandardXYItemRenderer();
    cashFlowRenderer.setSeriesPaint(0, Color.blue);
    plot.setRenderer(1, cashFlowRenderer);
}

From source file:Methods.CalculusSecant.java

public static ChartPanel createChartSecant(XYDataset datasetFunction) {// Method that populates and returns a Chart Pannel object, uses an entering paramether for the equation dataset and a global variable for the iteration points data set 

    datasetPointsSecant();//w w  w  . ja v  a 2 s. c o m
    JFreeChart chart = ChartFactory.createXYLineChart("Equation Chart", "X Axys", "Y Axys", datasetFunction,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();//declaring a renderer used to plot more than one datatset on the table

    plot.setDataset(1, datasetPoints);
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesShapesVisible(1, false);
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, true);
    plot.setRenderer(1, renderer);

    return new ChartPanel(chart);

}

From source file:ch.zhaw.parallelComputing.view.Plotter.java

/**
 * Generates a plot for comparing to datasets
 * @param title the name of the plot/* ww  w  . j  av  a 2 s  .  c o  m*/
 * @param dataset1 the first data set for plotting
 * @param dataset2 the second data set for plotting
 * @return a chart object for displaying or saving as picture
 */
public static JFreeChart plot(String title, XYDataset dataset1, XYDataset dataset2) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title
            "Date", // x-axis label
            "Input Value", // y-axis label
            dataset1, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    XYPlot plot = chart.getXYPlot();

    Axis axis1 = plot.getRangeAxis(0);
    axis1.setLabelPaint(Color.red);

    NumberAxis axis2 = new NumberAxis("Twitter");
    axis2.setLabelPaint(Color.blue);
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setBaseShapesVisible(false);
    plot.setRenderer(1, renderer);

    return chart;
}