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

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

Introduction

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

Prototype

public int getRangeAxisCount() 

Source Link

Document

Returns the number of range axes.

Usage

From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java

/**
 * Sets the colours and gradients to be used when painting the given JFreeChart.
 * //from   w w  w  .  ja v  a 2 s . c om
 * @param chart
 *          The JFreeChart to make nice.
 */
public static void makeChartNice(JFreeChart chart) {
    Plot plot = chart.getPlot();
    chart.setBackgroundPaint(null);
    chart.setBorderStroke(new BasicStroke(1f));
    chart.setBorderPaint(new Color(0xDDDDDD));
    chart.setBorderVisible(true);

    // TODO Should we add an option for subtitles, this is where it would go.
    //        TextTitle subTitle = new TextTitle("What's up doc?",
    //             new Font("SansSerif", Font.BOLD, 8));
    //       chart.addSubtitle(subTitle);

    // overall plot
    plot.setOutlinePaint(null);
    plot.setInsets(new RectangleInsets(0, 5, 0, 5)); // also the overall chart panel
    plot.setBackgroundPaint(null);
    plot.setDrawingSupplier(new WabitDrawingSupplier());

    // legend
    LegendTitle legend = chart.getLegend();
    if (legend != null) {
        legend.setBorder(0, 0, 0, 0);
        legend.setBackgroundPaint(null);
        legend.setPadding(2, 2, 2, 2);
    }

    if (plot instanceof CategoryPlot) {
        CategoryPlot cplot = (CategoryPlot) plot;

        CategoryItemRenderer renderer = cplot.getRenderer();
        if (renderer instanceof BarRenderer) {
            BarRenderer brenderer = (BarRenderer) renderer;

            brenderer.setBarPainter(new StandardBarPainter());
            brenderer.setDrawBarOutline(false);
            brenderer.setShadowVisible(false);

            brenderer.setGradientPaintTransformer(
                    new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

        } else if (renderer instanceof LineAndShapeRenderer) {
            // it's all taken care of by WabitDrawingSupplier

        } else {
            logger.warn("I don't know how to make " + renderer + " pretty. Leaving ugly.");
        }

        cplot.setRangeGridlinePaint(Color.BLACK);
        cplot.setRangeGridlineStroke(GRIDLINE_STROKE);

        // axes
        for (int i = 0; i < cplot.getDomainAxisCount(); i++) {
            CategoryAxis axis = cplot.getDomainAxis(i);
            axis.setAxisLineVisible(false);
        }

        for (int i = 0; i < cplot.getRangeAxisCount(); i++) {
            ValueAxis axis = cplot.getRangeAxis(i);
            axis.setAxisLineVisible(false);
        }
    }

    if (plot instanceof MultiplePiePlot) {
        MultiplePiePlot mpplot = (MultiplePiePlot) plot;
        JFreeChart pchart = mpplot.getPieChart();
        PiePlot3DGradient pplot = (PiePlot3DGradient) pchart.getPlot();
        pplot.setBackgroundPaint(null);
        pplot.setOutlinePaint(null);

        pplot.setFaceGradientPaintTransformer(
                new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));
        pplot.setSideGradientPaintTransformer(
                new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

        CategoryDataset data = mpplot.getDataset();
        Color[][] colours = WabitDrawingSupplier.SERIES_COLOURS;

        //Set all colours
        for (int i = 0; i < colours.length; i++) {
            if (data.getColumnCount() >= i + 1) {
                pplot.setSectionOutlinePaint(data.getColumnKey(i), null);
                GradientPaint gradient = new GradientPaint(0, 0f, colours[i][0], 100, 0f, colours[i][1]);
                pplot.setSectionPaint(data.getColumnKey(i), gradient);
                gradient = new GradientPaint(0, 0f, colours[i][1], 100, 0f, colours[i][0]);
                pplot.setSidePaint(data.getColumnKey(i), gradient);
            }
        }
    }

    // Tweak the title font size
    chart.getTitle().setFont(chart.getTitle().getFont().deriveFont(14f));
    chart.getTitle().setPadding(5, 0, 5, 0);
    chart.setAntiAlias(true);

    // shrink padding
    chart.setPadding(new RectangleInsets(0, 0, 0, 0));
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.JFreeChartPlotEngine.java

private void setAxesFont(Font axesFont) {
    JFreeChart chart = getCurrentChart();
    if (chart != null) {
        Plot plot = chart.getPlot();//ww  w.j a v a 2s  .  c o  m

        if (plot instanceof CategoryPlot) {
            CategoryPlot categoryPlot = (CategoryPlot) plot;

            // first change range axes font
            int rangeAxisCount = categoryPlot.getRangeAxisCount();
            for (int i = 0; i < rangeAxisCount; ++i) {
                ValueAxis valueAxis = categoryPlot.getRangeAxis(i);
                if (valueAxis != null) {
                    valueAxis.setLabelFont(axesFont);
                    valueAxis.setTickLabelFont(axesFont);
                }
            }

            // then set domain axis font
            CategoryAxis domainAxis = categoryPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabelFont(axesFont);
                domainAxis.setTickLabelFont(axesFont);
            }

        } else {
            XYPlot xyPlot = (XYPlot) plot;

            // first change range axes font
            int rangeAxisCount = xyPlot.getRangeAxisCount();
            for (int i = 0; i < rangeAxisCount; ++i) {
                ValueAxis rangeAxis = xyPlot.getRangeAxis(i);
                if (rangeAxis != null) {
                    rangeAxis.setLabelFont(axesFont);
                    rangeAxis.setTickLabelFont(axesFont);
                }
            }

            // then set domain axis font
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabelFont(axesFont);
                domainAxis.setTickLabelFont(axesFont);
            }

        }
    }
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.JFreeChartPlotEngine.java

private void axisLineColorChanged(Color lineColor) {
    JFreeChart chart = getCurrentChart();
    if (chart != null) {
        Plot plot = chart.getPlot();//ww w.  j av a2 s.  co m
        if (plot instanceof CategoryPlot) {
            CategoryPlot categoryPlot = (CategoryPlot) plot;
            ChartAxisFactory.formatAxis(plotInstance.getCurrentPlotConfigurationClone(),
                    categoryPlot.getDomainAxis());
            int rangeAxisCount = categoryPlot.getRangeAxisCount();
            for (int i = 0; i < rangeAxisCount; ++i) {
                ValueAxis valueAxis = categoryPlot.getRangeAxis(i);
                if (valueAxis != null) {
                    ChartAxisFactory.formatAxis(plotInstance.getCurrentPlotConfigurationClone(), valueAxis);
                }
            }
        } else if (plot instanceof XYPlot) {
            XYPlot xyPlot = (XYPlot) plot;
            ChartAxisFactory.formatAxis(plotInstance.getCurrentPlotConfigurationClone(),
                    xyPlot.getDomainAxis());
            int rangeAxisCount = xyPlot.getRangeAxisCount();
            for (int i = 0; i < rangeAxisCount; ++i) {
                ValueAxis valueAxis = xyPlot.getRangeAxis(i);
                valueAxis.setAxisLinePaint(lineColor);
                if (valueAxis != null) {
                    ChartAxisFactory.formatAxis(plotInstance.getCurrentPlotConfigurationClone(), valueAxis);
                }
            }
        }
    }

}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.JFreeChartPlotEngine.java

private void axisLineWidthChanged(Float lineWidth) {
    JFreeChart chart = getCurrentChart();
    if (chart != null) {
        Plot plot = chart.getPlot();//from w ww .  j av  a  2  s .  co m
        BasicStroke stroke = new BasicStroke(lineWidth);
        if (plot instanceof CategoryPlot) {
            CategoryPlot categoryPlot = (CategoryPlot) plot;
            CategoryAxis domainAxis = categoryPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setAxisLineStroke(stroke);
            }
            int rangeAxisCount = categoryPlot.getRangeAxisCount();
            for (int i = 0; i < rangeAxisCount; ++i) {
                ValueAxis valueAxis = categoryPlot.getRangeAxis(i);
                if (valueAxis != null) {
                    valueAxis.setAxisLineStroke(stroke);
                }
            }
        } else if (plot instanceof XYPlot) {
            XYPlot xyPlot = (XYPlot) plot;
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setAxisLineStroke(stroke);
            }
            int rangeAxisCount = xyPlot.getRangeAxisCount();
            for (int i = 0; i < rangeAxisCount; ++i) {
                ValueAxis valueAxis = xyPlot.getRangeAxis(i);
                if (valueAxis != null) {
                    valueAxis.setAxisLineStroke(stroke);
                }
            }
        }
    }

}