Example usage for org.jfree.chart.axis NumberAxis setVerticalTickLabels

List of usage examples for org.jfree.chart.axis NumberAxis setVerticalTickLabels

Introduction

In this page you can find the example usage for org.jfree.chart.axis NumberAxis setVerticalTickLabels.

Prototype

public void setVerticalTickLabels(boolean flag) 

Source Link

Document

Sets the flag that controls whether the tick labels are displayed vertically (that is, rotated 90 degrees from horizontal).

Usage

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

private JFreeChart createChart(XYDataset dataset, boolean createLegend) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            null, // x axis label
            null, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, createLegend, // include legend
            true, // tooltips
            false // urls
    );/*from w  w w .j  a v a  2 s  . c  o m*/

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customization...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    DeviationRenderer renderer = new DeviationRenderer(true, false);

    // colors
    if (dataset.getSeriesCount() == 1) {
        renderer.setSeriesStroke(0, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
        renderer.setSeriesPaint(0, getColorProvider().getPointColor(1.0d));
    } else { // special case needed for avoiding devision by zero
        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            renderer.setSeriesStroke(i, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
            renderer.setSeriesPaint(i,
                    getColorProvider().getPointColor(1.0d - i / (double) (dataset.getSeriesCount() - 1)));
        }
    }
    // background for bounds
    if (plotBounds) {
        float[] dashArray = new float[] { 7, 14 };
        renderer.setSeriesStroke(boundsSeriesIndex,
                new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, dashArray, 0));
        renderer.setSeriesPaint(boundsSeriesIndex, Color.GRAY.brighter());
        renderer.setSeriesFillPaint(boundsSeriesIndex, Color.GRAY);
    }
    // alpha
    renderer.setAlpha(0.25f);

    plot.setRenderer(renderer);

    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    if (axis[INDEX] < 0) {
        xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US));
        xAxis.setLabel(SERIESINDEX_LABEL);
        Range range = getRangeForName(SERIESINDEX_LABEL);
        if (range == null) {
            xAxis.setAutoRange(true);
            xAxis.setAutoRangeStickyZero(false);
            xAxis.setAutoRangeIncludesZero(false);
        } else {
            xAxis.setRange(range, true, false);
        }
    } else {
        xAxis.setLabel(dataTable.getColumnName(axis[INDEX]));
        Range range = getRangeForDimension(axis[INDEX]);
        if (range == null) {
            xAxis.setAutoRange(true);
            xAxis.setAutoRangeStickyZero(false);
            xAxis.setAutoRangeIncludesZero(false);
        } else {
            xAxis.setRange(range, true, false);
        }
    }

    xAxis.setLabelFont(LABEL_FONT_BOLD);
    xAxis.setTickLabelFont(LABEL_FONT);
    xAxis.setVerticalTickLabels(isLabelRotating());

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setLabel(VALUEAXIS_LABEL);
    yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US));
    setYAxisRange(yAxis);

    yAxis.setLabelFont(LABEL_FONT_BOLD);
    yAxis.setTickLabelFont(LABEL_FONT);

    return chart;
}

From source file:org.pentaho.chart.plugin.jfreechart.JFreeChartFactoryEngine.java

private void initXYPlot(JFreeChart chart, ChartModel chartModel) {
    initPlot(chart, chartModel);/*from   ww  w.j a  va  2  s.com*/

    org.pentaho.chart.model.TwoAxisPlot twoAxisPlot = (org.pentaho.chart.model.TwoAxisPlot) chartModel
            .getPlot();
    XYPlot xyPlot = chart.getXYPlot();

    List<Integer> colors = getPlotColors(twoAxisPlot);

    for (int i = 0; i < colors.size(); i++) {
        for (int j = 0; j < xyPlot.getDatasetCount(); j++) {
            xyPlot.getRenderer(j).setSeriesPaint(i, new Color(0x00FFFFFF & colors.get(i)));
        }
    }

    Font domainAxisFont = ChartUtils.getFont(twoAxisPlot.getDomainAxis().getFontFamily(),
            twoAxisPlot.getDomainAxis().getFontStyle(), twoAxisPlot.getDomainAxis().getFontWeight(),
            twoAxisPlot.getDomainAxis().getFontSize());
    Font rangeAxisFont = ChartUtils.getFont(twoAxisPlot.getRangeAxis().getFontFamily(),
            twoAxisPlot.getRangeAxis().getFontStyle(), twoAxisPlot.getRangeAxis().getFontWeight(),
            twoAxisPlot.getRangeAxis().getFontSize());
    Font rangeTitleFont = ChartUtils.getFont(twoAxisPlot.getRangeAxis().getLegend().getFontFamily(),
            twoAxisPlot.getRangeAxis().getLegend().getFontStyle(),
            twoAxisPlot.getRangeAxis().getLegend().getFontWeight(),
            twoAxisPlot.getRangeAxis().getLegend().getFontSize());
    Font domainTitleFont = ChartUtils.getFont(twoAxisPlot.getDomainAxis().getLegend().getFontFamily(),
            twoAxisPlot.getDomainAxis().getLegend().getFontStyle(),
            twoAxisPlot.getDomainAxis().getLegend().getFontWeight(),
            twoAxisPlot.getDomainAxis().getLegend().getFontSize());

    NumberAxis domainAxis = (NumberAxis) xyPlot.getDomainAxis();
    NumberAxis rangeAxis = (NumberAxis) xyPlot.getRangeAxis();

    domainAxis.setAutoRangeIncludesZero(true);
    rangeAxis.setAutoRangeIncludesZero(true);

    AxesLabels axesLabels = getAxesLabels(chartModel);
    if ((axesLabels.rangeAxisLabel.length() > 0) && (rangeTitleFont != null)) {
        rangeAxis.setLabelFont(rangeTitleFont);
    }

    if ((axesLabels.domainAxisLabel.length() > 0) && (domainTitleFont != null)) {
        domainAxis.setLabelFont(domainTitleFont);
    }

    domainAxis.setVerticalTickLabels(
            twoAxisPlot.getHorizontalAxis().getLabelOrientation() == LabelOrientation.VERTICAL);

    if (domainAxisFont != null) {
        domainAxis.setTickLabelFont(domainAxisFont);
    }
    if (rangeAxisFont != null) {
        rangeAxis.setTickLabelFont(rangeAxisFont);
    }

    Number rangeMin = ((NumericAxis) twoAxisPlot.getRangeAxis()).getMinValue();
    if (rangeMin != null) {
        rangeAxis.setLowerBound(rangeMin.doubleValue());
    }
    Number rangeMax = ((NumericAxis) twoAxisPlot.getRangeAxis()).getMaxValue();
    if (rangeMax != null) {
        rangeAxis.setUpperBound(rangeMax.doubleValue());
    }
}