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:cn.edu.thss.iise.bpmdemo.charts.SWTMultipleAxisDemo1.java

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

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Day(), 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 Day(), 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 Day(), 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 Day(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

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

    return chart;
}

From source file:control.JGeraGraficos.java

private static JFreeChart createGraficoXY(String title, String categoryAxisLabel, String valueAxisLabel,
        IntervalXYDataset dataset) {/*from   w  ww.j  a va2s. c  om*/

    NumberAxis domainAxis = new NumberAxis(categoryAxisLabel);
    domainAxis.setAutoRangeIncludesZero(false);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);

    XYBarRenderer renderer = new ClusteredXYBarRenderer();

    XYPlot plot = new XYPlot((XYDataset) dataset, domainAxis, valueAxis, renderer);

    plot.setOrientation(PlotOrientation.VERTICAL);

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    return chart;
}

From source file:com.projity.pm.graphic.chart.ChartHelper.java

public static JFreeChart createLineChart(final XYDataset dataset) {
    NumberAxis xAxis = new NumberAxis(null);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(null);
    XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    removeAxisAndInsets(chart);/*from   w ww  .j  ava  2 s  .co m*/
    return chart;
}

From source file:com.projity.pm.graphic.chart.ChartHelper.java

/**
 * Creates a new chart.// w w w.j  a va 2s.  c o m
 * 
 * @param dataset
 *            the dataset.
 * 
 * @return The chart.
 */
public static JFreeChart createBarChart(final XYDataset dataset) {
    ValueAxis domainAxis = null;
    NumberAxis axis = new NumberAxis(null);
    axis.setAutoRangeIncludesZero(false);
    domainAxis = axis;

    ValueAxis valueAxis = new NumberAxis(null);
    XYItemRenderer barRenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA,
            new StandardXYToolTipGenerator(), null);

    XYPlot plot = new XYPlot(dataset, domainAxis, valueAxis, barRenderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    removeAxisAndInsets(chart);
    return chart;
}

From source file:net.sf.maltcms.chromaui.charts.tools.ChartTools.java

/**
 *
 * @param plot// w w w . j a  va  2 s. co  m
 * @return
 */
public static XYPlot getPlot3(XYPlot plot) {
    XYPlot p = new XYPlot(plot.getDataset(), new NumberAxis(plot.getRangeAxis().getLabel()),
            new NumberAxis(plot.getDomainAxis().getLabel()), plot.getRenderer());
    p.setOrientation(PlotOrientation.HORIZONTAL);
    p.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
    Logger.getLogger(ChartTools.class.getName()).log(Level.INFO, "fixed auto range: {0}",
            plot.getRangeAxis().getRange().getUpperBound());
    p.getDomainAxis().setFixedAutoRange(500);

    return p;
}

From source file:com.orange.atk.results.logger.documentGenerator.GraphGenerator.java

/**
 * This function creates the measurement graph by using the JFreeChart
 * library. The X axis of the graph is in minutes.
 * //from   w  ww.  jav a 2  s  .  c  om
 * @param plotList
 *            plotlist to save. Xvalues must be stored in milliseconds.
 * @param associatedName
 *            Name of the list
 * @param folderWhereResultsAreSaved
 *            folder where results are saved
 * @param yLabel
 *            Name of the y label
 * @param pictureFile
 *            name of the file
 * @param yDivisor
 *            use to divide measurements stored in the plotlist by yDivisor
 */
public static void generateGraphWithJFreeChart(PlotList plotList, String associatedName,
        String folderWhereResultsAreSaved, String yLabel, String pictureFile, float yDivisor) {

    // Create a new XYSeries
    // XYSeries are used to represent couples of (x,y) values.
    XYSeries data = new XYSeries(associatedName);

    int size = plotList.getSize();
    if (size == 0) {
        // no element in graphics, exit
        //Logger.getLogger(this.getClass() ).warn("Nothing in graph");
        return;
    }

    // Find the initial value of the time
    // Due to the fact that getX(i) <= getX(i+1),
    // min({0<=i<size / getX(i)}) = getX(0)
    long initialValue = plotList.getX(0);

    XYSeriesCollection series = new XYSeriesCollection(data);
    if (!plotList.getunit().equals(""))
        yLabel += " (" + plotList.getunit() + ")";
    // Create a new XY graph.
    //JFreeChart chart = ChartFactory.createXYLineChart("", "Time", yLabel, series, PlotOrientation.VERTICAL, true, true, false);
    JFreeChart chart = ChartFactory.createTimeSeriesChart("", "Time (min:sec)", yLabel, series, true, true,
            false);
    // Set the graph format
    XYPlot plot = chart.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    //axis.setTickUnit(new DateTickUnit(DateTickUnit.SECOND, 10));
    RelativeDateFormat rdf = new RelativeDateFormat(initialValue);
    rdf.setSecondFormatter(new DecimalFormat("00"));
    axis.setDateFormatOverride(rdf);

    // Fill the JFreeChart object which will be used to create the Graph
    for (int i = 0; i < size; i++) {
        // xvalue must be in
        double xval = ((Long) plotList.getX(i)).doubleValue();
        float yval = plotList.getY(i).floatValue() / yDivisor;
        // Logger.getLogger(this.getClass() ).debug(associatedName + " [" + (((Long)
        // plotList.getX(i)).floatValue() - initialValue)
        // / XDIVISOR +"] "+ yval);
        data.add(xval, yval);
    }

    ValueAxis rangeAxis = plot.getRangeAxis();
    Long min = plotList.getMin();
    Long max = plotList.getMax();
    double diff = (max - min) * 0.02;
    if (diff == 0)
        diff = max * 0.0001;

    rangeAxis.setLowerBound((min - diff) / yDivisor);
    rangeAxis.setUpperBound((max + diff) / yDivisor);
    //      Logger.getLogger(this.getClass() ).debug("(" + (min / yDivisor) * 0.98 + " - "
    //            + (min / yDivisor) * 0.98 + ")");
    //      Logger.getLogger(this.getClass() ).debug("Bound = " + rangeAxis.getLowerBound() + " - "
    //            + rangeAxis.getUpperBound());
    //      Logger.getLogger(this.getClass() ).debug("Margin = " + rangeAxis.getLowerMargin() + " - "
    //            + rangeAxis.getUpperMargin());
    //      Logger.getLogger(this.getClass() ).debug("NB AXIS = " + plot.getRangeAxisCount());

    // save the chart in a picture file.
    BufferedImage bufImage = chart.createBufferedImage(640, 480);
    File fichier = new File(pictureFile);
    try {
        if (!ImageIO.write(bufImage, "png", fichier)) {
            return;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

}

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

private static JFreeChart createStackedXYBarChart(final String title, final String xAxisLabel,
        final boolean dateAxis, final String yAxisLabel, final TableXYDataset dataset,
        final PlotOrientation orientation, final boolean legend, final boolean tooltips, final boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }//from w  w w. j  a  v a 2  s  .c  om
    ValueAxis domainAxis = null;
    if (dateAxis) {
        domainAxis = new DateAxis(xAxisLabel);
    } else {
        final NumberAxis axis = new NumberAxis(xAxisLabel);
        axis.setAutoRangeIncludesZero(false);
        domainAxis = axis;
    }
    final ValueAxis valueAxis = new NumberAxis(yAxisLabel);

    final StackedXYBarRenderer renderer = new StackedXYBarRenderer();
    renderer.setUseYInterval(true);
    if (tooltips) {
        final XYToolTipGenerator tt;
        if (dateAxis) {
            tt = StandardXYToolTipGenerator.getTimeSeriesInstance();
        } else {
            tt = new StandardXYToolTipGenerator();
        }
        renderer.setBaseToolTipGenerator(tt);
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    final XYPlot plot = new XYPlot(dataset, domainAxis, valueAxis, renderer);
    plot.setOrientation(orientation);

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

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

/**
 * Creates and returns a default instance of an XY bar chart.
 * <p/>/* www . ja  va  2 s  .com*/
 * The chart object returned by this method uses an {@link XYPlot} instance as the plot, with a {@link
 * org.jfree.chart.axis.DateAxis} for the domain axis, a {@link org.jfree.chart.axis.NumberAxis} as the range axis,
 * and a {@link XYBarRenderer} 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 dateAxis    make the domain axis display dates?
 * @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 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 An XY bar chart.
 */
public static JFreeChart createXYBarChart(final String title, final String xAxisLabel, final boolean dateAxis,
        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.");
    }
    ValueAxis domainAxis = null;
    if (dateAxis) {
        domainAxis = new DateAxis(xAxisLabel);
    } else {
        final NumberAxis axis = new NumberAxis(xAxisLabel);
        axis.setAutoRangeIncludesZero(false);
        domainAxis = axis;
    }
    final ValueAxis valueAxis = new NumberAxis(yAxisLabel);

    final XYBarRenderer renderer = new XYBarRenderer();
    renderer.setUseYInterval(true);
    if (tooltips) {
        final XYToolTipGenerator tt;
        if (dateAxis) {
            tt = StandardXYToolTipGenerator.getTimeSeriesInstance();
        } else {
            tt = new StandardXYToolTipGenerator();
        }
        renderer.setBaseToolTipGenerator(tt);
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    final XYPlot plot = new XYPlot(dataset, domainAxis, valueAxis, renderer);
    plot.setOrientation(orientation);

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

From source file:org.gumtree.vis.plot1d.Plot1D.java

/**
 * Creates a line chart (based on an {@link XYDataset}) with default
 * settings.//from w  w  w  .j  ava 2  s  .c om
 *
 * @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 The chart.
 */
public static JFreeChart createXYLineChart(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);
    LogarithmizableAxis xAxis = new LogarithmizableAxis(xAxisLabel);

    xAxis.setLogarithmic(false);
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setAllowNegativesFlag(true);
    xAxis.setLowerMargin(0.02);
    xAxis.setUpperMargin(0.02);
    //        NumberAxis yAxis = new NumberAxis(yAxisLabel);
    LogarithmizableAxis yAxis = new LogarithmizableAxis(yAxisLabel);
    yAxis.setAllowNegativesFlag(true);
    yAxis.setAutoRangeNextLogFlag(false);
    yAxis.setLowerMargin(0.02);
    yAxis.setUpperMargin(0.02);
    yAxis.setLogarithmic(false);
    XYErrorRenderer renderer = new XYErrorRenderer();
    renderer.setBaseLinesVisible(true);
    renderer.setBaseShapesVisible(false);
    renderer.setDrawYError(true);
    //        XYItemRenderer renderer = new XYLineAndShapeRenderer(true, 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);
    chartTheme.apply(chart);
    return chart;

}

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

private static JFreeChart createCustomXYStepChart(TimePeriodValuesCollection prices) {
    DateAxis xAxis = new DateAxis(null);
    NumberAxis yAxis = new NumberAxis("price");
    yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());

    XYPlot plot = new XYPlot(prices, xAxis, yAxis, null);
    plot.setRenderer(new XYStepRenderer(null, null));
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}