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:web.diva.server.unused.ProfilePlotGenerator.java

/**
 * Creates a line chart (based on an {@link XYDataset}) with default
 * settings./*from   w w w.  j  av  a 2 s .co  m*/
 *
 * @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.
 */
private JFreeChart createXYLineChart(String title, String[] columnIds, XYDataset dataset,
        PlotOrientation orientation, boolean legend, boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    Font f = new Font("ARIAL", 1, 7);
    //        NumberAxis xAxis = new NumberAxis(xAxisLabel);
    //        xAxis.setAutoRangeIncludesZero(false);
    SymbolAxis xAxis = new SymbolAxis("", columnIds);
    xAxis.setAxisLineVisible(false);
    xAxis.setGridBandsVisible(false);
    xAxis.setVerticalTickLabels(true);
    xAxis.setVisible(true);

    xAxis.setTickLabelPaint(shadowColor);
    xAxis.setTickLabelFont(f);
    xAxis.setFixedDimension(51.0);

    boolean auto = xAxis.getAutoRangeIncludesZero();
    xAxis.setAutoRangeIncludesZero(true ^ auto);
    xAxis.setTickUnit(new NumberTickUnit(1));
    xAxis.setRange(0, columnIds.length);
    //        NumberAxis yAxis = new NumberAxis(yAxisLabel);
    NumberAxis yAxis = new NumberAxis();
    yAxis.setAutoRangeIncludesZero(true ^ auto);
    yAxis.setAxisLineVisible(false);
    yAxis.setTickLabelFont(f);
    yAxis.setTickLabelPaint(Color.BLUE);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setBaseShapesVisible(false);
    renderer.setPaint(shadowColor);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);

    plot.setBackgroundPaint(Color.WHITE);

    plot.setDomainGridlinePaint(shadowColor);
    plot.setRangeGridlinePaint(shadowColor);
    plot.setOutlinePaint(Color.BLUE);
    //        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    //        plot.setRenderer(renderer);
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.REVERSE);

    plot.setDomainAxis(xAxis);

    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    return 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 {/*from   ww w .  j  a  va  2  s. 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.vanosten.dings.swing.SummaryView.java

public void displayTimeSeriesChart(final TimeSeriesCollection averageScore, final int maxScoreRange,
        final TimeSeriesCollection numberOfEntries, final int maxTotalRange) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time Series", "Date", "Average Score",
            averageScore, true, true, false);

    chart.setBackgroundPaint(Color.white);
    final XYPlot plot = chart.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYItemRenderer renderer1 = plot.getRenderer();
    renderer1.setPaint(Color.blue);

    //axis 1//from   ww  w.j  a v  a2  s .com
    final NumberAxis axis1 = new NumberAxis("Average Score");
    axis1.setLabelPaint(Color.blue);
    axis1.setTickLabelPaint(Color.blue);
    axis1.setRange(0.0d, maxScoreRange + 1);
    plot.setRangeAxis(0, axis1);

    //axis 2
    final NumberAxis axis2 = new NumberAxis("Number of Entries");
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    axis2.setRange(0.0d, 10 * (((int) (maxTotalRange / 10)) + 1));
    plot.setRangeAxis(1, axis2);

    plot.setDataset(1, numberOfEntries);
    plot.mapDatasetToRangeAxis(1, 1);
    final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setPaint(Color.red);
    plot.setRenderer(1, renderer2);

    placeChart(chart);
}

From source file:playground.yu.utils.charts.XYScatterLineChart.java

private JFreeChart createChart(final String title, final String categoryAxisLabel, final String valueAxisLabel,
        final XYSeriesCollection dataset) {
    // return ChartFactory.createScatterPlot(title, categoryAxisLabel,
    // valueAxisLabel, dataset, PlotOrientation.VERTICAL, true, // legend?
    // false, // tooltips?
    // false // URLs?
    // );//from  ww  w.j  a  va  2 s  .c  o  m
    NumberAxis xAxis = new NumberAxis(categoryAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setRange(0, 24);
    NumberAxis yAxis = new NumberAxis(valueAxisLabel);
    yAxis.setAutoRangeIncludesZero(true);
    yAxis.setRange(0, 100);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);

    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, true);
    renderer.setBaseToolTipGenerator(null/* XYToolTipGenerator */);
    renderer.setURLGenerator(null/* urlGenerator */);
    plot.setRenderer(renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true/* legend */);
    return chart;
}

From source file:edu.umn.ecology.populus.plot.BasicPlotCanvas.java

private void jbInit() throws Exception {
    /*//from  w ww. j  ava  2 s.c  om
    if( info != null ) {
       mainCaption = new HTMLLabel( info.getMainCaption() );
       xCaption = new HTMLLabel( info.getXCaptions()[0] );
       yCaption = new HTMLLabel( info.getYCaptions()[0] );
       yCaption.setDirection( HTMLLabel.DOWN_TO_UP );
    } else {
       mainCaption = new HTMLLabel( "Main Caption" );
       xCaption = new HTMLLabel( "X Caption" );
       yCaption = new HTMLLabel( "Y Caption" );
    }
     */
    //*
    if (info != null) {
        mainCaption = new HTMLMultiLabel(info.getMainCaption());
        xCaption = new HTMLMultiLabel(info.getXCaptions());
        yCaption = new HTMLMultiLabel(info.getYCaptions());
        yCaption.setDirection(HTMLLabel.DOWN_TO_UP);
    } else {
        mainCaption = new HTMLMultiLabel("Main Caption");
        xCaption = new HTMLMultiLabel("X Caption");
        yCaption = new HTMLMultiLabel("Y Caption");
        yCaption.setDirection(HTMLLabel.DOWN_TO_UP);
    }
    setLayout(borderLayout1);
    if (PopPreferencesStorage.isUseJFreeClass()) {
        NumberAxis yAxis = new NumberAxis(null);
        NumberAxis xAxis = new NumberAxis(null);
        xAxis.setAutoRangeIncludesZero(false);

        AbstractXYItemRenderer renderer = null;
        if (info.isBarChart) {
            renderer = new XYBarRenderer();
        } else {
            renderer = new XYLineAndShapeRenderer(true, false);
        }

        XYPlot plot = new XYPlot(null, xAxis, yAxis, renderer);
        plot.setOrientation(PlotOrientation.VERTICAL);

        JFreeChart jfchart = new JFreeChart(null, null, plot, false);
        jfchartpanel = new ChartPanel(jfchart);
        plot.setBackgroundPaint(ColorScheme.bG);

        info.styleJFree(jfchart);
        add(jfchartpanel, MacroLayout.CENTER);
    } else {
        chart = new JCChart(JCChart.PLOT);
        info.styleJC(chart);
        chart.setBackground(ColorScheme.bG);
        chart.setAllowUserChanges(true);
        chart.setTrigger(0, new EventTrigger(InputEvent.SHIFT_MASK, EventTrigger.CUSTOMIZE));
        chart.setTrigger(1, new EventTrigger(InputEvent.BUTTON1_MASK, EventTrigger.ZOOM));
        chart.setResetKey('r');
        chart.addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseClicked(java.awt.event.MouseEvent e) {
                if ((e.getModifiers() & InputEvent.META_MASK) != 0) {
                    info.setAxis(chart);
                    chart.reset();
                }
            }
        });
        chart.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
        chart.setWarningDialog(false);
        add(chart, MacroLayout.CENTER);
    }
    setBGColor();
    add(mainCaption, MacroLayout.NORTH);
    add(xCaption, MacroLayout.SOUTH);
    add(yCaption, MacroLayout.WEST);
}

From source file:ucar.unidata.idv.control.chart.VerticalProfileChart.java

/**
 * Initialize the plot//from   w  ww .  j  a v  a2s. c o  m
 *
 * @param plot the plot to initialize
 */
protected void initPlot(Plot plot) {
    XYPlot xyPlot = (XYPlot) plot;
    xyPlot.setOrientation(PlotOrientation.HORIZONTAL);

    int count = xyPlot.getDatasetCount();
    for (int i = 0; i < count; i++) {
        xyPlot.setDataset(i, null);
        xyPlot.setRenderer(i, null);
    }
    xyPlot.clearRangeAxes();
    XYSeriesCollection dummyDataset = new XYSeriesCollection();
    //ValueAxis          rangeAxis    = new FixedWidthNumberAxis();
    ValueAxis rangeAxis = new NumberAxis();
    xyPlot.setRangeAxis(0, rangeAxis, false);
    xyPlot.setDataset(0, dummyDataset);
    xyPlot.mapDatasetToRangeAxis(0, 0);
    xyPlot.setRenderer(0, new XYLineAndShapeRenderer());
}

From source file:org.jstockchart.plot.TimeseriesPlot.java

private XYPlot createPricePlot() {
    Font axisFont = new Font("Arial", 0, 12);
    Stroke stroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f,
            new float[] { 1.0f, 1.0f }, 1.0f);
    PriceArea priceArea = timeseriesArea.getPriceArea();
    Color averageColor = new Color(243, 182, 117);
    priceArea.setAverageColor(averageColor);
    priceArea.setPriceColor(Color.BLUE);
    TimeSeriesCollection priceDataset = new TimeSeriesCollection();
    priceDataset.addSeries(dataset.getPriceTimeSeries().getTimeSeries());
    if (priceArea.isAverageVisible()) {
        priceDataset.addSeries(dataset.getAverageTimeSeries().getTimeSeries());
    }/*from  www  . j  av a2  s .c om*/

    CentralValueAxis logicPriceAxis = priceArea.getLogicPriceAxis();

    logicPriceAxis.setTickCount(7);

    CFXNumberAxis priceAxis = new CFXNumberAxis(logicPriceAxis.getLogicTicks());
    priceAxis.setShowUD(true);
    priceAxis.setOpenPrice(logicPriceAxis.getCentralValue().doubleValue());
    priceAxis.setTickMarksVisible(false);
    XYLineAndShapeRenderer priceRenderer = new XYLineAndShapeRenderer(true, false);
    priceAxis.setUpperBound(logicPriceAxis.getUpperBound());
    priceAxis.setLowerBound(logicPriceAxis.getLowerBound());
    priceAxis.setAxisLineVisible(false);
    priceAxis.setTickLabelFont(axisFont);
    priceRenderer.setSeriesPaint(0, priceArea.getPriceColor());
    priceRenderer.setSeriesPaint(1, priceArea.getAverageColor());

    CFXNumberAxis rateAxis = new CFXNumberAxis(logicPriceAxis.getRatelogicTicks());
    rateAxis.setShowUD(true);
    rateAxis.setOpenPrice(logicPriceAxis.getCentralValue().doubleValue());
    rateAxis.setTickMarksVisible(false);
    ;
    rateAxis.setTickLabelFont(axisFont);
    rateAxis.setAxisLineVisible(false);
    rateAxis.setUpperBound(logicPriceAxis.getUpperBound());
    rateAxis.setLowerBound(logicPriceAxis.getLowerBound());
    XYPlot plot = new XYPlot(priceDataset, null, priceAxis, priceRenderer);
    plot.setBackgroundPaint(priceArea.getBackgroudColor());
    plot.setOrientation(priceArea.getOrientation());
    plot.setRangeAxisLocation(priceArea.getPriceAxisLocation());
    plot.setRangeMinorGridlinesVisible(false);

    Stroke outLineStroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f,
            new float[] { 1.0f, 1.0f }, 1.0f);
    Stroke gridLineStroke = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f,
            new float[] { 2.0f, 2.0f }, 1.0f);

    plot.setRangeGridlineStroke(gridLineStroke);
    plot.setDomainGridlineStroke(gridLineStroke);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);
    plot.setOutlineVisible(true);
    plot.setOutlineStroke(outLineStroke);
    plot.setOutlinePaint(Color.BLACK);

    if (priceArea.isRateVisible()) {
        plot.setRangeAxis(1, rateAxis);
        plot.setRangeAxisLocation(1, priceArea.getRateAxisLocation());
        plot.setDataset(1, null);
        plot.mapDatasetToRangeAxis(1, 1);
    }

    if (priceArea.isMarkCentralValue()) {
        Number centralPrice = logicPriceAxis.getCentralValue();
        if (centralPrice != null) {
            plot.addRangeMarker(new ValueMarker(centralPrice.doubleValue(), priceArea.getCentralPriceColor(),
                    new BasicStroke()));
        }
    }
    return plot;
}

From source file:org.jstockchart.plot.TimeseriesPlot.java

private XYPlot createVolumePlot() {
    Font axisFont = new Font("Arial", 0, 12);
    Stroke stroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f,
            new float[] { 1.0f, 1.0f }, 1.0f);
    VolumeArea volumeArea = timeseriesArea.getVolumeArea();
    LogicNumberAxis logicVolumeAxis = volumeArea.getLogicVolumeAxis();
    Color volumeColor = new Color(86, 126, 160);
    volumeArea.setVolumeColor(volumeColor);
    CFXNumberAxis volumeAxis = new CFXNumberAxis(logicVolumeAxis.getLogicTicks());
    volumeAxis.setAxisLineVisible(false);
    volumeAxis.setCustomTickCount(2);/*from  ww  w.j  a v a2  s .c  om*/
    volumeAxis.setTickLabelPaint(volumeColor);
    volumeAxis.setUpperBound(logicVolumeAxis.getUpperBound());
    volumeAxis.setTickLabelFont(axisFont);
    volumeAxis.setTickMarkStroke(stroke);
    volumeAxis.setLowerBound(logicVolumeAxis.getLowerBound());
    volumeAxis.setAutoRangeIncludesZero(true);
    XYAreaRenderer2 volumeRenderer = new XYAreaRenderer2();
    volumeRenderer.setSeriesPaint(0, volumeArea.getVolumeColor());
    //volumeRenderer.setShadowVisible(false);
    volumeRenderer.setSeriesStroke(0, stroke);
    volumeRenderer.setBaseStroke(stroke);
    XYPlot plot = new XYPlot(new TimeSeriesCollection(dataset.getVolumeTimeSeries()), null, volumeAxis,
            volumeRenderer);
    plot.setBackgroundPaint(volumeArea.getBackgroudColor());
    plot.setOrientation(volumeArea.getOrientation());
    plot.setRangeAxisLocation(volumeArea.getVolumeAxisLocation());
    plot.setRangeMinorGridlinesVisible(false);

    Stroke outLineStroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f,
            new float[] { 1.0f, 1.0f }, 1.0f);
    Stroke gridLineStroke = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f,
            new float[] { 2.0f, 2.0f }, 1.0f);
    // plot.setBackgroundPaint(Color.RED);
    plot.setRangeGridlineStroke(gridLineStroke);
    plot.setDomainGridlineStroke(gridLineStroke);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);
    plot.setOutlineVisible(true);
    plot.setOutlineStroke(outLineStroke);
    plot.setOutlinePaint(Color.black);
    plot.setRangeZeroBaselineVisible(true);
    return plot;
}

From source file:com.anrisoftware.prefdialog.miscswing.multichart.freechart.FreechartXYChart.java

@OnAwt
@Override// w  w  w.j a v  a 2  s  .  co m
public void setPlotOrientation(PlotOrientation orientation) {
    PlotOrientation oldValue = this.orientation;
    if (oldValue == orientation) {
        return;
    }
    this.orientation = orientation;
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(toFreechartOrientation(orientation));
}

From source file:org.locationtech.udig.processingtoolbox.tools.ScatterPlotDialog.java

private void createGraphTab(final CTabFolder parentTabFolder) {
    plotTab = new CTabItem(parentTabFolder, SWT.NONE);
    plotTab.setText(Messages.ScatterPlotDialog_Graph);

    XYPlot plot = new XYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(java.awt.Color.WHITE);
    plot.setDomainPannable(false);//from  w ww .  j av  a  2  s. co m
    plot.setRangePannable(false);
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);

    JFreeChart chart = new JFreeChart(EMPTY, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBackgroundPaint(java.awt.Color.WHITE);
    chart.setBorderVisible(false);

    chartComposite = new ChartComposite2(parentTabFolder, SWT.NONE | SWT.EMBEDDED, chart, true);
    chartComposite.setLayout(new FillLayout());
    chartComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    chartComposite.setDomainZoomable(false);
    chartComposite.setRangeZoomable(false);
    chartComposite.setMap(map);
    chartComposite.addChartMouseListener(new PlotMouseListener());

    plotTab.setControl(chartComposite);

    chartComposite.pack();
}