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

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

Introduction

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

Prototype

public int getRangeAxisCount() 

Source Link

Document

Returns the number of range axes.

Usage

From source file:org.yccheok.jstock.charting.Utils.java

/**
 * Applying chart theme based on given JFreeChart.
 *
 * @param chart the JFreeChart/* www  . j a va  2  s. co  m*/
 */
public static void applyChartTheme(JFreeChart chart) {
    final StandardChartTheme chartTheme = (StandardChartTheme) org.jfree.chart.StandardChartTheme
            .createJFreeTheme();
    chartTheme.setXYBarPainter(barPainter);
    chartTheme.setShadowVisible(false);
    chartTheme.setPlotBackgroundPaint(Color.WHITE);
    chartTheme.setDomainGridlinePaint(Color.LIGHT_GRAY);
    chartTheme.setRangeGridlinePaint(Color.LIGHT_GRAY);
    chartTheme.setPlotOutlinePaint(Color.LIGHT_GRAY);

    // The default font used by JFreeChart unable to render Chinese properly.
    // We need to provide font which is able to support Chinese rendering.
    final Locale defaultLocale = Locale.getDefault();
    if (org.yccheok.jstock.gui.Utils.isSimplifiedChinese(defaultLocale)
            || org.yccheok.jstock.gui.Utils.isTraditionalChinese(defaultLocale)) {
        final Font oldExtraLargeFont = chartTheme.getExtraLargeFont();
        final Font oldLargeFont = chartTheme.getLargeFont();
        final Font oldRegularFont = chartTheme.getRegularFont();
        final Font oldSmallFont = chartTheme.getSmallFont();

        final Font extraLargeFont = new Font("Sans-serif", oldExtraLargeFont.getStyle(),
                oldExtraLargeFont.getSize());
        final Font largeFont = new Font("Sans-serif", oldLargeFont.getStyle(), oldLargeFont.getSize());
        final Font regularFont = new Font("Sans-serif", oldRegularFont.getStyle(), oldRegularFont.getSize());
        final Font smallFont = new Font("Sans-serif", oldSmallFont.getStyle(), oldSmallFont.getSize());

        chartTheme.setExtraLargeFont(extraLargeFont);
        chartTheme.setLargeFont(largeFont);
        chartTheme.setRegularFont(regularFont);
        chartTheme.setSmallFont(smallFont);
    }

    if (chart.getPlot() instanceof CombinedDomainXYPlot) {
        @SuppressWarnings("unchecked")
        List<Plot> plots = ((CombinedDomainXYPlot) chart.getPlot()).getSubplots();
        for (Plot plot : plots) {
            final int domainAxisCount = ((XYPlot) plot).getDomainAxisCount();
            final int rangeAxisCount = ((XYPlot) plot).getRangeAxisCount();
            for (int i = 0; i < domainAxisCount; i++) {
                ((XYPlot) plot).getDomainAxis(i).setAxisLinePaint(Color.LIGHT_GRAY);
                ((XYPlot) plot).getDomainAxis(i).setTickMarkPaint(Color.LIGHT_GRAY);
            }
            for (int i = 0; i < rangeAxisCount; i++) {
                ((XYPlot) plot).getRangeAxis(i).setAxisLinePaint(Color.LIGHT_GRAY);
                ((XYPlot) plot).getRangeAxis(i).setTickMarkPaint(Color.LIGHT_GRAY);
            }
        }
    } else {
        final Plot plot = chart.getPlot();
        if (plot instanceof XYPlot) {
            final org.jfree.chart.plot.XYPlot xyPlot = (org.jfree.chart.plot.XYPlot) plot;
            final int domainAxisCount = xyPlot.getDomainAxisCount();
            final int rangeAxisCount = xyPlot.getRangeAxisCount();
            for (int i = 0; i < domainAxisCount; i++) {
                xyPlot.getDomainAxis(i).setAxisLinePaint(Color.LIGHT_GRAY);
                xyPlot.getDomainAxis(i).setTickMarkPaint(Color.LIGHT_GRAY);
            }
            for (int i = 0; i < rangeAxisCount; i++) {
                xyPlot.getRangeAxis(i).setAxisLinePaint(Color.LIGHT_GRAY);
                xyPlot.getRangeAxis(i).setTickMarkPaint(Color.LIGHT_GRAY);
            }
        }
        //else if (plot instanceof org.jfree.chart.plot.PiePlot) {
        //    final org.jfree.chart.plot.PiePlot piePlot = (org.jfree.chart.plot.PiePlot)plot;
        //    
        //}
    }

    chartTheme.apply(chart);
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

public static Point2D translateChartPoint(Point2D point, Rectangle2D imageArea, JFreeChart chart,
        int rangeAxisIndex) {
    XYPlot plot = chart.getXYPlot();
    double x, y;//from  w  w w  .  j a  va 2s  . c o m

    ValueAxis domainAxis = plot.getDomainAxis();
    ValueAxis rangeAxis;
    if (rangeAxisIndex < 0 || rangeAxisIndex >= plot.getRangeAxisCount()) {
        rangeAxis = plot.getRangeAxis();
    } else {
        rangeAxis = plot.getRangeAxis(rangeAxisIndex);
    }
    x = domainAxis.valueToJava2D(point.getX(), imageArea, RectangleEdge.BOTTOM);
    y = rangeAxis.valueToJava2D(point.getY(), imageArea, RectangleEdge.LEFT);

    return new Point2D.Double(x, y);
}

From source file:edu.wisc.ssec.mcidasv.control.McIDASVHistogramWrapper.java

/**
 * reset the histogram to its previous range
 *///from w w  w.  j  a  v  a2 s .c om
public void resetPlot() {
    if (chart == null) {
        return;
    }
    if (!(chart.getPlot() instanceof XYPlot)) {
        return;
    }
    XYPlot plot = (XYPlot) chart.getPlot();
    int rcnt = plot.getRangeAxisCount();
    for (int i = 0; i < rcnt; i++) {
        ValueAxis axis = plot.getRangeAxis(i);
        axis.setAutoRange(true);
    }
    int dcnt = plot.getDomainAxisCount();
    for (int i = 0; i < dcnt; i++) {
        ValueAxis axis = plot.getDomainAxis(i);
        try {
            axis.setRange(low, high);
        } catch (Exception e) {
            logger.warn("jfreechart does not like ranges to be high -> low", e);
        }
    }
}

From source file:P251.graphPanel.java

/**
   resizes the axis to the given limits/* w  w  w. ja va  2  s .c o  m*/
 */
public void resizeAxis(double d0, double d1, double r0, double r1) {
    XYPlot plot = (XYPlot) chart.getChart().getPlot();
    plot.getDomainAxis().setAutoRange(false);
    plot.getDomainAxis().setRange(d0, d1);
    plot.getRangeAxis().setAutoRange(false);
    plot.getRangeAxis().setRange(r0, r1);
    System.out.println(plot.getDomainAxisCount());
    System.out.println(plot.getRangeAxisCount());

    // plot.getRangeAxis().setDefaultAutoRange(new Range(0,1));

}

From source file:com.rapidminer.gui.new_plotter.gui.dialog.AddParallelLineDialog.java

/**
 * Updates the preselected y-value./*from  ww  w.j a  v a2s .c  o  m*/
 */
private void updateYFieldValue() {
    // update preselected y value because range axis has been changed
    if (mousePosition != null) {
        Rectangle2D plotArea = engine.getChartPanel().getScreenDataArea();
        if (engine.getChartPanel().getChart().getPlot() instanceof XYPlot) {
            XYPlot plot = (XYPlot) engine.getChartPanel().getChart().getPlot();

            // calculate y value
            for (int i = 0; i < plot.getRangeAxisCount(); i++) {
                ValueAxis config = plot.getRangeAxis(i);
                if (config != null && config.getLabel() != null) {
                    if (config.getLabel()
                            .equals(String.valueOf(rangeAxisSelectionCombobox.getSelectedItem()))) {
                        double chartY = config.java2DToValue(mousePosition.getY(), plotArea,
                                plot.getRangeAxisEdge());
                        yField.setText(String.valueOf(chartY));
                    }
                }
            }
        }
    }
}

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

/**
 * Move plot up/down.//from w w  w  .j  a  v a 2  s  . co  m
 *
 * @param up up
 */
private void upDownPlot(boolean up) {
    if (!(plot instanceof XYPlot)) {
        return;
    }
    XYPlot xyPlot = (XYPlot) plot;

    int cnt = xyPlot.getRangeAxisCount();
    for (int i = 0; i < cnt; i++) {
        ValueAxis axis = (ValueAxis) xyPlot.getRangeAxis(i);
        org.jfree.data.Range range = axis.getRange();
        double width = range.getUpperBound() - range.getLowerBound();
        double width2 = width / 2.0;
        double step = (up ? width * 0.1 : -width * 0.1);
        axis.centerRange(range.getLowerBound() + step + width2);
    }
}

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

/**
 * Move plot up/down./*from  w ww  . j  a v a2  s.  c  o  m*/
 *
 * @param up up
 */
private void upDownPlot(boolean up) {
    if (!(chart.getPlot() instanceof XYPlot)) {
        return;
    }
    XYPlot plot = (XYPlot) chart.getPlot();

    int cnt = plot.getRangeAxisCount();
    for (int i = 0; i < cnt; i++) {
        ValueAxis axis = (ValueAxis) plot.getRangeAxis(i);
        org.jfree.data.Range range = axis.getRange();
        double width = range.getUpperBound() - range.getLowerBound();
        double width2 = width / 2.0;
        double step = (up ? width * 0.1 : -width * 0.1);
        axis.centerRange(range.getLowerBound() + step + width2);
    }
}

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

/**
 * reset the axis'/*from www.j  a  v a2  s  .  c  o  m*/
 */
private void resetPlot() {
    if (chart == null) {
        return;
    }
    if (!(chart.getPlot() instanceof XYPlot)) {
        return;
    }
    XYPlot plot = (XYPlot) chart.getPlot();
    int rcnt = plot.getRangeAxisCount();
    for (int i = 0; i < rcnt; i++) {
        ValueAxis axis = (ValueAxis) plot.getRangeAxis(i);
        System.err.println("range axis:" + axis);
        axis.setAutoRange(autoRange);
    }
    int dcnt = plot.getDomainAxisCount();
    for (int i = 0; i < dcnt; i++) {
        ValueAxis axis = (ValueAxis) plot.getDomainAxis(i);
        System.err.println("domain axis:" + axis);
        axis.setAutoRange(autoRange);
    }
}

From source file:com.rapidminer.gui.plotter.charts.ChartPanelShiftController.java

/**
 * Returns the ValueAxis for the plot or <code>null</code> if the plot doesn't have one.
 * /*ww  w  .  j a  v  a 2 s .co  m*/
 * @param chart
 *            The chart
 * @param domain
 *            True = get Domain axis. False = get Range axis.
 * @return The selected ValueAxis or <code>null</code> if the plot doesn't have one.
 */
protected ValueAxis[] getPlotAxis(JFreeChart chart, boolean domain) {
    // Where's the Shiftable interface when we need it ?? ;)
    Plot plot = chart.getPlot();
    if (plot instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) plot;
        // return domain ? ((XYPlot) plot).getDomainAxis() : ((XYPlot) plot).getRangeAxis();
        if (domain) {
            ValueAxis[] rangeAxes = new ValueAxis[xyPlot.getDomainAxisCount()];
            for (int i = 0; i < rangeAxes.length; i++) {
                rangeAxes[i] = xyPlot.getDomainAxis(i);
            }
            return rangeAxes;
        } else {
            ValueAxis[] rangeAxes = new ValueAxis[xyPlot.getRangeAxisCount()];
            for (int i = 0; i < rangeAxes.length; i++) {
                rangeAxes[i] = xyPlot.getRangeAxis(i);
            }
            return rangeAxes;
        }
    }
    if (plot instanceof FastScatterPlot) {
        return domain ? new ValueAxis[] { ((FastScatterPlot) plot).getDomainAxis() }
                : new ValueAxis[] { ((FastScatterPlot) plot).getRangeAxis() };
    }
    return null;
}

From source file:mil.tatrc.physiology.utilities.csv.plots.CSVPlotTool.java

public void formatXYPlot(JFreeChart chart, Paint bgColor) {
    XYPlot plot = (XYPlot) chart.getPlot();

    //For Scientific notation
    NumberFormat formatter = new DecimalFormat("0.######E0");

    for (int i = 0; i < plot.getDomainAxisCount(); i++) {
        plot.getDomainAxis(i).setLabelFont(largeFont);
        plot.getDomainAxis(i).setTickLabelFont(smallFont);
        plot.getDomainAxis(i).setLabelPaint(bgColor == Color.red ? Color.white : Color.black);
        plot.getDomainAxis(i).setTickLabelPaint(bgColor == Color.red ? Color.white : Color.black);
    }/*from  w  w  w.  j a v  a2  s  .  c om*/
    for (int i = 0; i < plot.getRangeAxisCount(); i++) {
        plot.getRangeAxis(i).setLabelFont(largeFont);
        plot.getRangeAxis(i).setTickLabelFont(smallFont);
        plot.getRangeAxis(i).setLabelPaint(bgColor == Color.red ? Color.white : Color.black);
        plot.getRangeAxis(i).setTickLabelPaint(bgColor == Color.red ? Color.white : Color.black);
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(i);
        rangeAxis.setNumberFormatOverride(formatter);
    }

    //White background outside of plottable area
    chart.setBackgroundPaint(bgColor);

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    chart.getLegend().setItemFont(smallFont);
    chart.getTitle().setFont(largeFont);
    chart.getTitle().setPaint(bgColor == Color.red ? Color.white : Color.black);
}