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

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

Introduction

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

Prototype

public void setOrientation(PlotOrientation orientation) 

Source Link

Document

Sets the orientation for the plot and sends a PlotChangeEvent to all registered listeners.

Usage

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

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset("March 2007", 100D, new Day(1, 3, 2007), 31);
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 4", "Date", "Value",
            xydataset, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setOrientation(PlotOrientation.VERTICAL);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setDateFormatOverride(new SimpleDateFormat("d-MMM-yyyy"));
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setSeriesPaint(0, Color.red);
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setTickLabelPaint(Color.red);
    DateAxis dateaxis1 = new DateAxis("Date");
    dateaxis1.setDateFormatOverride(new SimpleDateFormat("d-MMM-yyyy"));
    xyplot.setDomainAxis(1, dateaxis1);/*ww w  . j av a  2 s .c o m*/
    xyplot.setDomainAxisLocation(1, AxisLocation.TOP_OR_LEFT);
    NumberAxis numberaxis1 = new NumberAxis("Value");
    numberaxis1.setAutoRangeIncludesZero(false);
    numberaxis1.setTickLabelPaint(Color.blue);
    xyplot.setRangeAxis(1, numberaxis1);
    xyplot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    XYDataset xydataset1 = createDataset("July 2007", 1000D, new Day(1, 7, 2007), 31);
    xyplot.setDataset(1, xydataset1);
    xyplot.mapDatasetToDomainAxis(1, 1);
    xyplot.mapDatasetToRangeAxis(1, 1);
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false);
    xylineandshaperenderer.setSeriesPaint(0, Color.blue);
    xyplot.setRenderer(1, xylineandshaperenderer);
    return jfreechart;
}

From source file:com.itemanalysis.jmetrik.graph.histogram.HistogramChart.java

public static JFreeChart createHistogram(String title, String xAxisLabel, String yAxisLabel,
        IntervalXYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips,
        boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }//  www .  j ava2s  .c o m
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    ValueAxis yAxis = new NumberAxis(yAxisLabel);

    XYItemRenderer renderer = new XYBarRenderer();
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}

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

private static JFreeChart createChart(BoxAndWhiskerXYDataset boxandwhiskerxydataset) {
    DateAxis dateaxis = new DateAxis("Day");
    NumberAxis numberaxis = new NumberAxis("Value");
    XYBoxAndWhiskerRenderer xyboxandwhiskerrenderer = new XYBoxAndWhiskerRenderer();
    XYPlot xyplot = new XYPlot(boxandwhiskerxydataset, dateaxis, numberaxis, xyboxandwhiskerrenderer);
    xyplot.setOrientation(PlotOrientation.HORIZONTAL);
    JFreeChart jfreechart = new JFreeChart("Box-and-Whisker Chart Demo 2", xyplot);
    jfreechart.setBackgroundPaint(Color.white);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setDomainGridlinesVisible(true);
    xyplot.setRangeGridlinePaint(Color.white);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return jfreechart;
}

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

public static JPanel createDemoPanel() {
    JPanel jpanel = new JPanel(new GridLayout(2, 2));
    jpanel.setPreferredSize(new Dimension(800, 600));
    IntervalXYDataset intervalxydataset = createDataset();
    JFreeChart jfreechart = createChart("Vertical", intervalxydataset);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setDrawBarOutline(false);
    xybarrenderer.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow));
    xybarrenderer.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green));
    xybarrenderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    jpanel.add(chartpanel);//from   ww  w.  j a  v  a 2 s .  c  o  m
    JFreeChart jfreechart1 = createChart("Vertical / Inverted Axis", intervalxydataset);
    XYPlot xyplot1 = (XYPlot) jfreechart1.getPlot();
    XYBarRenderer xybarrenderer1 = (XYBarRenderer) xyplot1.getRenderer();
    xybarrenderer1.setDrawBarOutline(false);
    xybarrenderer1.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow));
    xybarrenderer1.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green));
    xybarrenderer1.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));
    xyplot1.getDomainAxis().setInverted(true);
    ChartPanel chartpanel1 = new ChartPanel(jfreechart1);
    jpanel.add(chartpanel1);
    JFreeChart jfreechart2 = createChart("Horizontal", intervalxydataset);
    XYPlot xyplot2 = (XYPlot) jfreechart2.getPlot();
    xyplot2.setOrientation(PlotOrientation.HORIZONTAL);
    XYBarRenderer xybarrenderer2 = (XYBarRenderer) xyplot2.getRenderer();
    xybarrenderer2.setDrawBarOutline(false);
    xybarrenderer2.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow));
    xybarrenderer2.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green));
    xybarrenderer2.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_VERTICAL));
    ChartPanel chartpanel2 = new ChartPanel(jfreechart2);
    jpanel.add(chartpanel2);
    JFreeChart jfreechart3 = createChart("Horizontal / Inverted Axis", intervalxydataset);
    XYPlot xyplot3 = (XYPlot) jfreechart3.getPlot();
    xyplot3.setOrientation(PlotOrientation.HORIZONTAL);
    XYBarRenderer xybarrenderer3 = (XYBarRenderer) xyplot3.getRenderer();
    xybarrenderer3.setDrawBarOutline(false);
    xybarrenderer3.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow));
    xybarrenderer3.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green));
    xybarrenderer3.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL));
    xyplot3.getDomainAxis().setInverted(true);
    ChartPanel chartpanel3 = new ChartPanel(jfreechart3);
    jpanel.add(chartpanel3);
    return jpanel;
}

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

private static JFreeChart createChart(XYZDataset xyzdataset) {
    DateAxis dateaxis = new DateAxis("Date");
    dateaxis.setLowerMargin(0.0D);//from w  ww.j  a  va  2s . c o m
    dateaxis.setUpperMargin(0.0D);
    dateaxis.setInverted(true);
    NumberAxis numberaxis = new NumberAxis("Hour");
    numberaxis.setUpperMargin(0.0D);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    XYBlockRenderer xyblockrenderer = new XYBlockRenderer();
    xyblockrenderer.setBlockWidth(86400000D);
    xyblockrenderer.setBlockAnchor(RectangleAnchor.BOTTOM_LEFT);
    LookupPaintScale lookuppaintscale = new LookupPaintScale(0.5D, 4.5D, Color.white);
    lookuppaintscale.add(0.5D, Color.red);
    lookuppaintscale.add(1.5D, Color.green);
    lookuppaintscale.add(2.5D, Color.blue);
    lookuppaintscale.add(3.5D, Color.yellow);
    xyblockrenderer.setPaintScale(lookuppaintscale);
    XYPlot xyplot = new XYPlot(xyzdataset, dateaxis, numberaxis, xyblockrenderer);
    xyplot.setOrientation(PlotOrientation.HORIZONTAL);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    JFreeChart jfreechart = new JFreeChart("XYBlockChartDemo2", xyplot);
    jfreechart.removeLegend();
    jfreechart.setBackgroundPaint(Color.white);
    SymbolAxis symbolaxis = new SymbolAxis(null,
            new String[] { "", "Unavailable", "Free", "Group 1", "Group 2" });
    symbolaxis.setRange(0.5D, 4.5D);
    symbolaxis.setPlot(new PiePlot());
    symbolaxis.setGridBandsVisible(false);
    PaintScaleLegend paintscalelegend = new PaintScaleLegend(lookuppaintscale, symbolaxis);
    paintscalelegend.setMargin(new RectangleInsets(3D, 10D, 3D, 10D));
    paintscalelegend.setPosition(RectangleEdge.BOTTOM);
    paintscalelegend.setAxisOffset(5D);
    jfreechart.addSubtitle(paintscalelegend);
    return jfreechart;
}

From source file:jamel.gui.charts.Histogram.java

/**
 * Returns a new plot./*from   ww w .ja  v  a  2  s.  co  m*/
 * @param dataset  the dataset.
 * @param hAxisLabel  the label for the x axis.
 * @param vAxisLabel  the label for the y axis.
 * @param color  the color of the chart.
 * @return the new plot.
 */
static private Plot newPlot(HistogramDataset dataset, String hAxisLabel, String vAxisLabel, Color color) {
    NumberAxis xAxis = new NumberAxis(hAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    ValueAxis yAxis = new NumberAxis(vAxisLabel);
    XYBarRenderer renderer = new XYBarRenderer();
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setShadowVisible(false);
    renderer.setMargin(0.05);
    renderer.setSeriesPaint(0, color);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);
    return plot;
}

From source file:graph.jfreecharts.GraphFunction.java

/**
 * A custom xyerror renderer because jfreecharts does not
 * have it supported in the api.// w  w w  . j  a v  a2  s . c o  m
 * @param title the graph title
 * @param xAxisLabel the xaxis title
 * @param yAxisLabel the yaxis title
 * @param dataset the xydataset
 * @param orientation the plot orientation
 * @param legend true to turn on legend
 * @param tooltips true to turn on tooltips (the pop up when right click)
 * @param urls // no idea what this is for
 * @return
 */
private static JFreeChart createXYIntervalChart(String title, String xAxisLabel, String yAxisLabel,
        XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYErrorRenderer renderer = new XYErrorRenderer();

    renderer.setDrawXError(true);
    renderer.setDrawYError(true);

    xAxis.setNumberFormatOverride(new DecimalFormat("0.######E0"));
    yAxis.setNumberFormatOverride(new DecimalFormat("0.######E0"));

    xAxis.setAutoRangeIncludesZero(false);
    yAxis.setAutoRangeIncludesZero(false);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;

}

From source file:org.pentaho.plugin.jfreereport.reportcharts.XYAreaChartExpression.java

/**
 * Creates a stacked XY area plot.  The chart object returned by this method uses an {@link
 * org.jfree.chart.plot.XYPlot} instance as the plot, with a {@link org.jfree.chart.axis.NumberAxis} for the domain
 * axis, a {@link org.jfree.chart.axis.NumberAxis} as the range axis, and a {@link
 * org.jfree.chart.renderer.xy.StackedXYAreaRenderer2} as the renderer.
 *
 * @param title       the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset     the dataset for the chart (<code>null</code> permitted).
 * @param orientation the plot orientation (horizontal or vertical) (<code>null</code> NOT permitted).
 * @param legend      a flag specifying whether or not a legend is required.
 * @param tooltips    configure chart to generate tool tips?
 * @param urls        configure chart to generate URLs?
 * @return A stacked XY area chart./*from  w w  w  . j a  v  a 2s . c om*/
 */
protected static JFreeChart createStackedXYAreaChart(final String title, final String xAxisLabel,
        final String yAxisLabel, final XYDataset dataset, final PlotOrientation orientation,
        final boolean legend, final boolean tooltips, final boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    final NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    final NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = new StandardXYToolTipGenerator();
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }
    final StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(toolTipGenerator, urlGenerator);
    renderer.setOutline(true);
    final XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);

    plot.setRangeAxis(yAxis); // forces recalculation of the axis range

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

From source file:jamel.gui.charts.AbstractScatterChart.java

/**
 * Returns a new plot./*from w  w w . j av a2s . c  om*/
 * 
 * @param xySeries  the series.
 * @param xAxisLabel  the label of the horizontal axis.
 * @param yAxisLabel  the label of the vertical axis.
 * @return a new plot.
 */
static private Plot newPlot(XYSeries xySeries, String xAxisLabel, String yAxisLabel) {
    final XYSeriesCollection dataset = new XYSeriesCollection();
    if (xySeries != null)
        dataset.addSeries(xySeries);
    final XYPlot plot = new XYPlot(dataset, new NumberAxis(xAxisLabel), new NumberAxis(yAxisLabel),
            new XYLineAndShapeRenderer(false, true));
    plot.setOrientation(PlotOrientation.VERTICAL);
    return plot;
}

From source file:org.jfree.chart.swt.demo.SWTMultipleAxisDemo1.java

/**
 * Creates the demo chart.//w  ww  .  j  av  a2  s . c  o m
 *
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200);

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 3", "Time of Day",
            "Primary Range Axis", dataset1, true, true, false);

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");
    chart.addSubtitle(subtitle);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);

    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    //axis3.setPositiveArrowVisible(true);
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(), 170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}