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

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

Introduction

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

Prototype

public void setDatasetRenderingOrder(DatasetRenderingOrder order) 

Source Link

Document

Sets the rendering order and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:ta4jexamples.indicators.CandlestickChart.java

public static void main(String[] args) {
    /**// w ww.  j  av  a 2  s .co 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:ec.nbdemetra.benchmarking.calendarization.CalendarizationChartView.java

private static JFreeChart createChart(String title) {
    JFreeChart result = ChartFactory.createXYLineChart("", "", "", Charts.emptyXYDataset(),
            PlotOrientation.VERTICAL, false, false, false);
    result.setPadding(TsCharts.CHART_PADDING);

    result.setTitle(new TextTitle(title, new Font("SansSerif", Font.PLAIN, 12)));

    XYPlot plot = result.getXYPlot();
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    LinesThickness linesThickness = LinesThickness.Thin;

    XYLineAndShapeRenderer daily = new XYLineAndShapeRenderer(true, false);
    daily.setAutoPopulateSeriesPaint(false);

    daily.setAutoPopulateSeriesStroke(false);
    daily.setBaseStroke(TsCharts.getStrongStroke(linesThickness));
    plot.setRenderer(DAILY_INDEX, daily);

    XYDifferenceRenderer difference = new XYDifferenceRenderer();
    difference.setAutoPopulateSeriesPaint(false);
    difference.setAutoPopulateSeriesStroke(false);
    difference.setBaseStroke(TsCharts.getNormalStroke(linesThickness));
    plot.setRenderer(DIFF_INDEX, difference);

    XYLineAndShapeRenderer smooth = new XYLineAndShapeRenderer(true, false);
    smooth.setAutoPopulateSeriesPaint(false);
    smooth.setAutoPopulateSeriesStroke(false);
    smooth.setBaseStroke(TsCharts.getStrongStroke(linesThickness));
    plot.setRenderer(SMOOTH_INDEX, smooth);

    DateAxis domainAxis = new DateAxis();
    domainAxis.setTickMarkPosition(DateTickMarkPosition.START);
    domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setDomainAxis(domainAxis);//  w w  w  .j  a v  a2 s. c  o  m

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setRangeAxis(rangeAxis);

    return result;
}

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

/**
 * Creates a new dataset for visualizing the fitted function.
 * <p>//from  w ww . ja v  a 2 s  . co  m
 * The new dataset is added to the end of the dataset list of the given plot.
 * </p>
 * 
 * @param aPlot Plot to which the new dataset must be added.
 * @return Index of the newly created dataset in the dataset list of <code>aPlot</code>.
 */
protected static int createDataset(XYPlot aPlot) {
    int i = aPlot.getDatasetCount();
    aPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    XYLineAndShapeRenderer rend = new XYLineAndShapeRenderer();
    rend.setSeriesLinesVisible(0, true);
    rend.setSeriesShapesVisible(0, false);
    aPlot.setRenderer(i, rend);
    return i;
}

From source file:temp1.RealTimeChart.java

public static JFreeChart createChart(String chartContent, String title, String yaxisName) {
    thread1 = new Thread();
    timeseries1 = new TimeSeries(chartContent, Millisecond.class);
    timeseries2 = new TimeSeries(chartContent, Millisecond.class);
    timeseries3 = new TimeSeries(chartContent, Millisecond.class);
    timeseries4 = new TimeSeries(chartContent, Millisecond.class);

    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeseries1);
    TimeSeriesCollection timeseriescollection1 = new TimeSeriesCollection(timeseries2);
    TimeSeriesCollection timeseriescollection2 = new TimeSeriesCollection(timeseries3);
    TimeSeriesCollection timeseriescollection3 = new TimeSeriesCollection(timeseries4);

    jfreechart = ChartFactory.createTimeSeriesChart("", "", "", timeseriescollection, false, false, false);

    final XYPlot xyplot = jfreechart.getXYPlot();
    xyplot.setOutlinePaint(Color.magenta);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setRangeGridlinePaint(Color.gray);
    xyplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    ValueAxis valueaxis = xyplot.getDomainAxis();
    valueaxis.setAutoRange(true);//from  ww w  . ja v  a 2 s  .  c o m
    valueaxis.setFixedAutoRange(20000D);
    //Value
    valueaxis = xyplot.getRangeAxis();
    valueaxis.setRange(800D, 3300D);
    xyplot.setDataset(0, timeseriescollection);
    xyplot.setDataset(1, timeseriescollection1);
    xyplot.setDataset(2, timeseriescollection2);
    xyplot.setDataset(3, timeseriescollection3);
    XYLineAndShapeRenderer xylineandshaperenderer0 = new XYLineAndShapeRenderer();
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer();
    XYLineAndShapeRenderer xylineandshaperenderer3 = new XYLineAndShapeRenderer();
    xylineandshaperenderer0.setBaseShapesVisible(false);
    xylineandshaperenderer1.setBaseShapesVisible(false);
    xylineandshaperenderer2.setBaseShapesVisible(false);
    xylineandshaperenderer3.setBaseShapesVisible(false);
    xylineandshaperenderer0.setSeriesPaint(0, Color.RED);
    xylineandshaperenderer1.setSeriesPaint(0, Color.cyan);
    xylineandshaperenderer2.setSeriesPaint(0, Color.yellow);
    xylineandshaperenderer3.setSeriesPaint(0, Color.blue);
    xyplot.setRenderer(0, xylineandshaperenderer0);
    xyplot.setRenderer(1, xylineandshaperenderer1);
    xyplot.setRenderer(2, xylineandshaperenderer2);
    xyplot.setRenderer(3, xylineandshaperenderer3);
    //xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(0.5F, 1, 1, 5F, new float[] { 5F, 10F }, 0.0F));
    return jfreechart;
}

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

public static JPanel createDemoPanel() {
    TimeSeries timeseries = new TimeSeries("Annual");
    timeseries.add(new Year(1998), 80D);
    timeseries.add(new Year(1999), 85D);
    timeseries.add(new Year(2000), 87.599999999999994D);
    TimeSeriesCollection dataset1 = new TimeSeriesCollection(timeseries);
    TimeSeries timeseries1 = new TimeSeries("Monthly A");
    timeseries1.add(new Month(7, 2000), 85.799999999999997D);
    timeseries1.add(new Month(8, 2000), 85.799999999999997D);
    timeseries1.add(new Month(9, 2000), 85.799999999999997D);
    timeseries1.add(new Month(10, 2000), 86.5D);
    timeseries1.add(new Month(11, 2000), 86.5D);
    timeseries1.add(new Month(12, 2000), 86.5D);
    timeseries1.add(new Month(1, 2001), 87.700000000000003D);
    timeseries1.add(new Month(2, 2001), 87.700000000000003D);
    timeseries1.add(new Month(3, 2001), 87.700000000000003D);
    timeseries1.add(new Month(4, 2001), 88.5D);
    timeseries1.add(new Month(5, 2001), 88.5D);
    timeseries1.add(new Month(6, 2001), 88.5D);
    timeseries1.add(new Month(7, 2001), 90D);
    timeseries1.add(new Month(8, 2001), 90D);
    timeseries1.add(new Month(9, 2001), 90D);
    timeseries1.add(new Month(10, 2001), 90D);
    timeseries1.add(new Month(11, 2001), 90D);
    timeseries1.add(new Month(12, 2001), 90D);
    timeseries1.add(new Month(1, 2002), 90D);
    timeseries1.add(new Month(2, 2002), 90D);
    timeseries1.add(new Month(3, 2002), 90D);
    timeseries1.add(new Month(4, 2002), 90D);
    timeseries1.add(new Month(5, 2002), 90D);
    timeseries1.add(new Month(6, 2002), 90D);
    TimeSeries timeseries2 = new TimeSeries("Monthly B");
    timeseries2.add(new Month(7, 2000), 83.799999999999997D);
    timeseries2.add(new Month(8, 2000), 83.799999999999997D);
    timeseries2.add(new Month(9, 2000), 83.799999999999997D);
    timeseries2.add(new Month(10, 2000), 84.5D);
    timeseries2.add(new Month(11, 2000), 84.5D);
    timeseries2.add(new Month(12, 2000), 84.5D);
    timeseries2.add(new Month(1, 2001), 85.700000000000003D);
    timeseries2.add(new Month(2, 2001), 85.700000000000003D);
    timeseries2.add(new Month(3, 2001), 85.700000000000003D);
    timeseries2.add(new Month(4, 2001), 86.5D);
    timeseries2.add(new Month(5, 2001), 86.5D);
    timeseries2.add(new Month(6, 2001), 86.5D);
    timeseries2.add(new Month(7, 2001), 88D);
    timeseries2.add(new Month(8, 2001), 88D);
    timeseries2.add(new Month(9, 2001), 88D);
    timeseries2.add(new Month(10, 2001), 88D);
    timeseries2.add(new Month(11, 2001), 88D);
    timeseries2.add(new Month(12, 2001), 88D);
    timeseries2.add(new Month(1, 2002), 88D);
    timeseries2.add(new Month(2, 2002), 88D);
    timeseries2.add(new Month(3, 2002), 88D);
    timeseries2.add(new Month(4, 2002), 88D);
    timeseries2.add(new Month(5, 2002), 88D);
    timeseries2.add(new Month(6, 2002), 88D);
    TimeSeriesCollection dataset21 = new TimeSeriesCollection();
    dataset21.addSeries(timeseries1);/*from   w  w  w  .ja  v  a2 s  . c  om*/
    dataset21.addSeries(timeseries2);
    TimeSeries timeseries3 = new TimeSeries("XXX");
    timeseries3.add(new Month(7, 2000), 81.5D);
    timeseries3.add(new Month(8, 2000), 86D);
    timeseries3.add(new Month(9, 2000), 82D);
    timeseries3.add(new Month(10, 2000), 89.5D);
    timeseries3.add(new Month(11, 2000), 88D);
    timeseries3.add(new Month(12, 2000), 88D);
    timeseries3.add(new Month(1, 2001), 90D);
    timeseries3.add(new Month(2, 2001), 89.5D);
    timeseries3.add(new Month(3, 2001), 90.200000000000003D);
    timeseries3.add(new Month(4, 2001), 90.599999999999994D);
    timeseries3.add(new Month(5, 2001), 87.5D);
    timeseries3.add(new Month(6, 2001), 91D);
    timeseries3.add(new Month(7, 2001), 89.700000000000003D);
    timeseries3.add(new Month(8, 2001), 87D);
    timeseries3.add(new Month(9, 2001), 91.200000000000003D);
    timeseries3.add(new Month(10, 2001), 84D);
    timeseries3.add(new Month(11, 2001), 90D);
    timeseries3.add(new Month(12, 2001), 92D);
    TimeSeriesCollection dataset22 = new TimeSeriesCollection(timeseries3);
    //
    XYBarRenderer renderer1 = new XYBarRenderer(0.20000000000000001D);
    renderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} ({1}, {2})",
            new SimpleDateFormat("yyyy"), new DecimalFormat("0.00")));
    XYPlot plot1 = new XYPlot(dataset1, new DateAxis("Date"), null, renderer1);
    //
    XYAreaRenderer renderer21 = new XYAreaRenderer();
    XYPlot plot2 = new XYPlot(dataset21, new DateAxis("Date"), null, renderer21);
    StandardXYItemRenderer renderer22 = new StandardXYItemRenderer(3);
    renderer22.setBaseShapesFilled(true);
    plot2.setDataset(1, dataset22);
    plot2.setRenderer(1, renderer22);
    plot2.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    //
    NumberAxis valueAxis = new NumberAxis("Value");
    valueAxis.setAutoRangeIncludesZero(false);
    CombinedRangeXYPlot combinedPlot = new CombinedRangeXYPlot(valueAxis);
    combinedPlot.add(plot1, 1);
    combinedPlot.add(plot2, 4);
    //chart
    JFreeChart jfreechart = new JFreeChart("Sample Combined Plot", JFreeChart.DEFAULT_TITLE_FONT, combinedPlot,
            true);
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setPreferredSize(new Dimension(500, 270));
    chartpanel.addChartMouseListener(new ChartMouseListener() {

        public void chartMouseClicked(ChartMouseEvent chartmouseevent) {
            System.out.println(chartmouseevent.getEntity());
        }

        public void chartMouseMoved(ChartMouseEvent chartmouseevent) {
            System.out.println(chartmouseevent.getEntity());
        }

    });
    return chartpanel;
}

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

private static JFreeChart createChart() {
    IntervalXYDataset dataset1 = createDataset1();
    XYBarRenderer renderer1 = new XYBarRenderer(0.20000000000000001D);
    renderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})",
            new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    DateAxis domainAxis = new DateAxis("Date");
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    NumberAxis valueAxis = new NumberAxis("Value");
    XYPlot plot = new XYPlot(dataset1, domainAxis, valueAxis, renderer1);
    XYDataset dataset2 = createDataset2();
    StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})",
            new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    plot.setDataset(1, dataset2);//  www  . j ava  2s.  com
    plot.setRenderer(1, renderer2);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    return new JFreeChart("Overlaid XYPlot Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}

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  va  2s. c  om*/
     * 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:org.operamasks.faces.render.graph.CompositeChartRenderer.java

private JFreeChart createXYCompositeChart(List<JFreeChart> subcharts, UIChart comp) {
    XYPlot compositePlot = new XYPlot();
    compositePlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    compositePlot.setOrientation(getChartOrientation(comp));

    for (int i = 0; i < subcharts.size(); i++) {
        XYPlot subplot = (XYPlot) subcharts.get(i).getPlot();
        compositePlot.setDataset(i, subplot.getDataset());
        compositePlot.setRenderer(i, subplot.getRenderer());

        if (i == 0) {
            compositePlot.setDomainAxis(0, subplot.getDomainAxis());
            compositePlot.setRangeAxis(0, subplot.getRangeAxis());
        } else {//ww w.j a v a2s . co m
            int yAxisMap = getRangeAxisMap(comp, i);
            ValueAxis yAxis = null;
            if (yAxisMap == -1) {
                yAxisMap = 0; // map to axis zero by default
            } else if (yAxisMap == i) {
                yAxis = subplot.getRangeAxis(); // add subplot axis to composite plot
            }
            compositePlot.setRangeAxis(i, yAxis);
            compositePlot.mapDatasetToRangeAxis(i, yAxisMap);
        }
    }

    return new JFreeChart(null, null, compositePlot, false);
}

From source file:net.commerce.zocalo.freechart.ChartGenerator.java

public static JFreeChart createOverlaidOHLCAndStepChart(TimePeriodValuesCollection bottom,
        TimePeriodValuesCollection top, OHLCDataset ohlCdata) {
    DateAxis xAxis = new DateAxis(null);
    NumberAxis yAxis = new NumberAxis("price");
    yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    yAxis.setUpperBound(100);/*from  w  w w  .jav a 2  s . c  o m*/
    yAxis.setLowerBound(0.0);

    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    plot.setDataset(0, bottom);
    plot.setDataset(1, top);
    plot.setDataset(2, ohlCdata);

    XYStepAreaRenderer bottomRenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA, null, null);
    XYStepAreaRenderer topRenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA, null, null);
    HighLowRenderer hiLoRenderer = new HighLowRenderer();

    topRenderer.setRangeBase(1.0);
    topRenderer.setSeriesPaint(0, new Color(204, 255, 153));
    bottomRenderer.setSeriesPaint(0, new Color(51, 255, 204));
    plot.setRenderer(bottomRenderer);
    plot.setRenderer(1, topRenderer);
    plot.setRenderer(2, hiLoRenderer);

    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}

From source file:org.amanzi.awe.charts.builder.TimeChartBuilder.java

@Override
protected void setSecondAxisForPlot(XYPlot plot, Dataset dataset, StandardXYItemRenderer subRenderer,
        NumberAxis secondAxis) {//www .  java  2s.  c  o  m
    plot.setRangeAxis(1, secondAxis);
    plot.setDataset(1, (XYDataset) dataset);
    plot.mapDatasetToRangeAxis(1, 1);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    plot.setRenderer(1, subRenderer);

}