Example usage for org.jfree.chart.plot CombinedRangeXYPlot setRenderer

List of usage examples for org.jfree.chart.plot CombinedRangeXYPlot setRenderer

Introduction

In this page you can find the example usage for org.jfree.chart.plot CombinedRangeXYPlot setRenderer.

Prototype

@Override
public void setRenderer(XYItemRenderer renderer) 

Source Link

Document

Sets the item renderer FOR ALL SUBPLOTS.

Usage

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

/**
 * Creates a horizontally combined chart.
 *
 * @return a horizontally combined chart.
 *///  ww w . j av  a  2 s .  c o  m
public JFreeChart createHorizontallyCombinedChart() {

    // create a default chart based on some sample data...
    final String title = this.resources.getString("combined.horizontal.title");
    final String subtitleStr = this.resources.getString("combined.horizontal.subtitle");
    final String[] domains = this.resources.getStringArray("combined.horizontal.domains");
    final String rangeAxisLabel = this.resources.getString("combined.horizontal.range");

    final TimeSeriesCollection dataset0 = new TimeSeriesCollection();
    final TimeSeries eur = DemoDatasetFactory.createEURTimeSeries();
    dataset0.addSeries(eur);

    final TimeSeriesCollection dataset1 = new TimeSeriesCollection();
    final TimeSeries mav = MovingAverage.createMovingAverage(eur, "EUR/GBP (30 Day MA)", 30, 30);
    dataset1.addSeries(eur);
    dataset1.addSeries(mav);

    final TimeSeriesCollection dataset2 = new TimeSeriesCollection();
    dataset2.addSeries(eur);

    // make a combined range plot
    final NumberAxis valueAxis = new NumberAxis(rangeAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false); // override default
    final CombinedRangeXYPlot parent = new CombinedRangeXYPlot(valueAxis);
    parent.setRenderer(new StandardXYItemRenderer());

    // add subplots
    final int[] weight = { 1, 1, 1 }; // controls space assigned to each subplot

    // add subplot 1...
    final XYPlot subplot1 = new XYPlot(dataset0, new DateAxis(domains[0]), null, new StandardXYItemRenderer());
    parent.add(subplot1, weight[0]);

    // add subplot 2...
    final XYPlot subplot2 = new XYPlot(dataset1, new DateAxis(domains[1]), null, new StandardXYItemRenderer());
    parent.add(subplot2, weight[1]);

    // add subplot 3...
    final XYPlot subplot3 = new XYPlot(dataset2, new DateAxis(domains[2]), null, new XYBarRenderer(0.20));
    parent.add(subplot3, weight[2]);

    // now make the top level JFreeChart
    final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, parent, true);

    // then customise it a little...
    final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12));
    chart.addSubtitle(subtitle);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));
    return chart;

}