Example usage for org.jfree.chart.axis CategoryLabelPosition CategoryLabelPosition

List of usage examples for org.jfree.chart.axis CategoryLabelPosition CategoryLabelPosition

Introduction

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

Prototype

public CategoryLabelPosition(RectangleAnchor categoryAnchor, TextBlockAnchor labelAnchor,
        TextAnchor rotationAnchor, double angle, CategoryLabelWidthType widthType, float widthRatio) 

Source Link

Document

Creates a new position record.

Usage

From source file:edu.coeia.charts.BarChartPanel.java

private JFreeChart createChart(final CategoryDataset dataset, String str) {
    final JFreeChart chart = ChartFactory.createBarChart3D(str, // chart title
            "Names", // domain axis label
            "Values(%)", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );/*from  w ww  . java2  s  . co m*/

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setForegroundAlpha(1.0f);

    // left align the category labels...
    final CategoryAxis axis = plot.getDomainAxis();
    final CategoryLabelPositions p = axis.getCategoryLabelPositions();

    final CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT,
            TextBlockAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0, CategoryLabelWidthType.RANGE, 0.30f);
    axis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left));

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(from, to);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.BarChart3DDemo2.java

/**
 * Creates a chart./* w w w  .j  av  a  2 s. co  m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createBarChart3D(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setForegroundAlpha(1.0f);

    // left align the category labels...
    CategoryAxis axis = plot.getDomainAxis();
    CategoryLabelPositions p = axis.getCategoryLabelPositions();

    CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT,
            TextAnchor.CENTER_LEFT, 0.0, CategoryLabelWidthType.RANGE, 0.30f);
    axis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left));

    BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer();
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());
    setCategorySummary(dataset);
    return chart;

}

From source file:eu.cassandra.training.utils.ChartUtils.java

/**
 * This function is used for the visualization of a Comparative Response Model
 * Histogram.//from   w ww. j av a 2  s .co m
 * 
 * @param title
 *          The title of the chart.
 * @param x
 *          The unit on the X axis of the chart.
 * @param y
 *          The unit on the Y axis of the chart.
 * @param dataBefore
 *          The array of values before the response.
 * @param dataAfter
 *          The array of values after the response.
 * @return a chart panel with the graphical representation.
 */
public static ChartPanel createDailyResponseHistogram(String title, String x, String y, double[] dataBefore,
        double[] dataAfter) {
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (int i = 0; i < dataBefore.length; i++) {
        dataset.addValue(dataBefore[i], "Basic Scheme", "" + i + "");
        if (i < dataAfter.length)
            dataset.addValue(dataAfter[i], "New Scheme", "" + i + "");
        else
            dataset.addValue(0, "New Scheme", "" + i + "");
    }

    JFreeChart chart = ChartFactory.createBarChart3D(title, // chart title
            x, // domain axis label
            y, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setForegroundAlpha(1.0f);

    // left align the category labels...
    final CategoryAxis axis = plot.getDomainAxis();
    final CategoryLabelPositions p = axis.getCategoryLabelPositions();

    final CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT,
            TextBlockAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0, CategoryLabelWidthType.RANGE, 0.30f);
    axis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left));

    return new ChartPanel(chart);
}

From source file:j2se.jfreechart.barchart.BarChart3DDemo2.java

/**
 * Creates a chart./*w  w  w.jav a2s.c  om*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createBarChart3D("3D Bar Chart Demo 2", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setForegroundAlpha(1.0f);

    // left align the category labels...
    final CategoryAxis axis = plot.getDomainAxis();
    final CategoryLabelPositions p = axis.getCategoryLabelPositions();

    final CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT,
            TextBlockAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0, CategoryLabelWidthType.RANGE, 0.30f);
    axis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left));

    return chart;

}

From source file:com.manydesigns.portofino.chart.Chart2DGenerator.java

public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    java.util.List<Object[]> result;
    String query = chartDefinition.getQuery();
    logger.info(query);/*from w  w  w.  jav a2  s . com*/
    Session session = persistence.getSession(chartDefinition.getDatabase());
    result = QueryUtils.runSql(session, query);
    for (Object[] current : result) {
        ComparableWrapper x = new ComparableWrapper((Comparable) current[0]);
        ComparableWrapper y = new ComparableWrapper((Comparable) current[1]);
        if (current.length > 3) {
            x.setLabel(current[3].toString());
        }
        if (current.length > 4) {
            y.setLabel(current[4].toString());
        }
        dataset.setValue((Number) current[2], x, y);
    }

    PlotOrientation plotOrientation = PlotOrientation.HORIZONTAL;
    if (chartDefinition.getActualOrientation() == ChartDefinition.Orientation.VERTICAL) {
        plotOrientation = PlotOrientation.VERTICAL;
    }

    JFreeChart chart = createChart(chartDefinition, dataset, plotOrientation);

    chart.setAntiAlias(antiAlias);

    // impostiamo il bordo invisibile
    // eventualmente e' il css a fornirne uno
    chart.setBorderVisible(borderVisible);

    // impostiamo il titolo
    TextTitle title = chart.getTitle();
    title.setFont(titleFont);
    title.setMargin(10.0, 0.0, 0.0, 0.0);

    // ottieni il Plot
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    CategoryItemRenderer renderer = plot.getRenderer();
    String urlExpression = chartDefinition.getUrlExpression();
    if (!StringUtils.isBlank(urlExpression)) {
        CategoryURLGenerator urlGenerator = new ChartBarUrlGenerator(chartDefinition.getUrlExpression());
        renderer.setBaseItemURLGenerator(urlGenerator);
    } else {
        renderer.setBaseItemURLGenerator(null);
    }
    renderer.setBaseOutlinePaint(Color.BLACK);

    // ///////////////
    if (renderer instanceof BarRenderer) {
        BarRenderer barRenderer = (BarRenderer) renderer;

        barRenderer.setDrawBarOutline(true);
        barRenderer.setShadowVisible(false);
        barRenderer.setBarPainter(new StandardBarPainter());
    }
    // ///////////////

    // il plot ha sfondo e bordo trasparente
    // (quindi si vede il colore del chart)
    plot.setBackgroundPaint(transparentColor);
    plot.setOutlinePaint(transparentColor);

    // Modifico il toolTip
    // plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} = {1} ({2})"));

    // imposta il messaggio se non ci sono dati
    plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available"));
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.GRAY);
    plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));

    // Category axis
    CategoryAxis categoryAxis = plot.getDomainAxis();
    categoryAxis.setAxisLinePaint(Color.BLACK);
    categoryAxis.setLabelFont(axisFont);
    categoryAxis.setAxisLineVisible(true);

    // impostiamo la rotazione dell'etichetta
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        CategoryLabelPosition pos = new CategoryLabelPosition(RectangleAnchor.TOP_LEFT,
                TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -Math.PI / 4.0,
                CategoryLabelWidthType.CATEGORY, 100);
        CategoryLabelPositions positions = new CategoryLabelPositions(pos, pos, pos, pos);
        categoryAxis.setCategoryLabelPositions(positions);
        categoryAxis.setMaximumCategoryLabelWidthRatio(6.0f);
        height = 333;
    } else {
        categoryAxis.setMaximumCategoryLabelWidthRatio(0.4f);

        // recuperiamo 8 pixel a sinistra
        plot.setInsets(new RectangleInsets(4.0, 0.0, 4.0, 8.0));

        height = 74;

        // contiamo gli elementi nel dataset
        height += 23 * dataset.getColumnCount();

        height += 57;
    }

    Axis rangeAxis = plot.getRangeAxis();
    rangeAxis.setAxisLinePaint(Color.BLACK);
    rangeAxis.setLabelFont(axisFont);

    DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier());
    plot.setDrawingSupplier(supplier);
    // ?
    plot.setForegroundAlpha(1.0f);
    // impostiamo il titolo della legenda
    String legendString = chartDefinition.getLegend();
    Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM,
            HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0));
    subtitle.setMargin(0, 0, 5, 0);
    chart.addSubtitle(subtitle);

    // impostiamo la legenda
    LegendTitle legend = chart.getLegend();
    legend.setBorder(0, 0, 0, 0);
    legend.setItemFont(legendItemFont);
    int legendMargin = 10;
    legend.setMargin(0.0, legendMargin, legendMargin, legendMargin);
    legend.setBackgroundPaint(transparentColor);

    // impostiamo un gradiente orizzontale
    Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, height, Color.WHITE);
    chart.setBackgroundPaint(chartBgPaint);
    return chart;
}

From source file:com.manydesigns.portofino.chart.ChartStackedBarGenerator.java

public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    java.util.List<Object[]> result;
    String query = chartDefinition.getQuery();
    logger.info(query);//  w  ww  . j  a  va 2s .  c o  m
    Session session = persistence.getSession(chartDefinition.getDatabase());
    result = QueryUtils.runSql(session, query);
    for (Object[] current : result) {
        ComparableWrapper x = new ComparableWrapper((Comparable) current[0]);
        ComparableWrapper y = new ComparableWrapper((Comparable) current[1]);
        if (current.length > 3) {
            x.setLabel(current[3].toString());
        }
        if (current.length > 4) {
            y.setLabel(current[4].toString());
        }
        dataset.setValue((Number) current[2], x, y);
    }

    PlotOrientation plotOrientation = PlotOrientation.HORIZONTAL;
    if (chartDefinition.getActualOrientation() == ChartDefinition.Orientation.VERTICAL) {
        plotOrientation = PlotOrientation.VERTICAL;
    }

    JFreeChart chart = createChart(chartDefinition, dataset, plotOrientation);

    chart.setAntiAlias(antiAlias);

    // impostiamo il bordo invisibile
    // eventualmente e' il css a fornirne uno
    chart.setBorderVisible(borderVisible);

    // impostiamo il titolo
    TextTitle title = chart.getTitle();
    title.setFont(titleFont);
    title.setMargin(10.0, 0.0, 0.0, 0.0);

    // ottieni il Plot
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    CategoryItemRenderer renderer = plot.getRenderer();
    String urlExpression = chartDefinition.getUrlExpression();
    if (!StringUtils.isBlank(urlExpression)) {
        CategoryURLGenerator urlGenerator = new ChartBarUrlGenerator(chartDefinition.getUrlExpression());
        renderer.setBaseItemURLGenerator(urlGenerator);
    } else {
        renderer.setBaseItemURLGenerator(null);
    }
    renderer.setBaseOutlinePaint(Color.BLACK);

    // ///////////////
    if (renderer instanceof BarRenderer) {
        BarRenderer barRenderer = (BarRenderer) renderer;

        barRenderer.setDrawBarOutline(true);
        barRenderer.setShadowVisible(false);
        barRenderer.setBarPainter(new StandardBarPainter());

        // hongliangpan add
        // ?
        barRenderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator());
        // bar???
        barRenderer.setMinimumBarLength(0.02);
        // 
        barRenderer.setMaximumBarWidth(0.06);
    }
    if (renderer instanceof StackedBarRenderer3D || renderer instanceof StackedBarRenderer) {
        BarRenderer barRenderer = (BarRenderer) renderer;
        barRenderer.setDrawBarOutline(true);
        barRenderer.setShadowVisible(false);
        barRenderer.setBarPainter(new StandardBarPainter());

        // hongliangpan add
        // ? setSeriesItemLabelGenerator
        barRenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        // bar???
        barRenderer.setMinimumBarLength(0.02);
        // 
        barRenderer.setMaximumBarWidth(0.06);
        // ?????
        ItemLabelPosition itemLabelPositionFallback = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                TextAnchor.BASELINE_LEFT, TextAnchor.HALF_ASCENT_LEFT, -1.57D);
        // ??labelposition
        barRenderer.setPositiveItemLabelPositionFallback(itemLabelPositionFallback);
        barRenderer.setNegativeItemLabelPositionFallback(itemLabelPositionFallback);

        barRenderer.setItemLabelsVisible(true);
        barRenderer.setItemMargin(10);
    }

    // ///////////////

    // il plot ha sfondo e bordo trasparente
    // (quindi si vede il colore del chart)
    plot.setBackgroundPaint(transparentColor);
    plot.setOutlinePaint(transparentColor);

    // Modifico il toolTip
    // plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} = {1} ({2})"));

    // imposta il messaggio se non ci sono dati
    plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available"));
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.GRAY);
    plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));

    // Category axis
    CategoryAxis categoryAxis = plot.getDomainAxis();
    categoryAxis.setAxisLinePaint(Color.BLACK);
    categoryAxis.setLabelFont(axisFont);
    categoryAxis.setAxisLineVisible(true);

    // impostiamo la rotazione dell'etichetta
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        CategoryLabelPosition pos = new CategoryLabelPosition(RectangleAnchor.TOP_LEFT,
                TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -Math.PI / 4.0,
                CategoryLabelWidthType.CATEGORY, 100);
        CategoryLabelPositions positions = new CategoryLabelPositions(pos, pos, pos, pos);
        categoryAxis.setCategoryLabelPositions(positions);
        categoryAxis.setMaximumCategoryLabelWidthRatio(6.0f);
        height = 333;
    } else {
        categoryAxis.setMaximumCategoryLabelWidthRatio(0.4f);

        // recuperiamo 8 pixel a sinistra
        plot.setInsets(new RectangleInsets(4.0, 0.0, 4.0, 8.0));

        height = 74;

        // contiamo gli elementi nel dataset
        height += 23 * dataset.getColumnCount();

        height += 57;
    }

    Axis rangeAxis = plot.getRangeAxis();
    rangeAxis.setAxisLinePaint(Color.BLACK);
    rangeAxis.setLabelFont(axisFont);

    DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier());
    plot.setDrawingSupplier(supplier);

    // impostiamo il titolo della legenda
    String legendString = chartDefinition.getLegend();
    Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM,
            HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0));
    subtitle.setMargin(0, 0, 5, 0);
    chart.addSubtitle(subtitle);

    // impostiamo la legenda
    LegendTitle legend = chart.getLegend();
    legend.setBorder(0, 0, 0, 0);
    legend.setItemFont(legendItemFont);
    int legendMargin = 10;
    legend.setMargin(0.0, legendMargin, legendMargin, legendMargin);
    legend.setBackgroundPaint(transparentColor);

    // impostiamo un gradiente orizzontale
    Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, height, Color.WHITE);
    chart.setBackgroundPaint(chartBgPaint);
    return chart;
}

From source file:com.manydesigns.portofino.chart.ChartBarGenerator.java

public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    java.util.List<Object[]> result;
    String query = chartDefinition.getQuery();
    logger.info(query);/*from   ww w . java  2  s .c  om*/
    Session session = persistence.getSession(chartDefinition.getDatabase());
    result = QueryUtils.runSql(session, query);
    for (Object[] current : result) {
        ComparableWrapper x = new ComparableWrapper((Comparable) current[0]);
        ComparableWrapper y = new ComparableWrapper((Comparable) current[1]);
        if (current.length > 3) {
            x.setLabel(current[3].toString());
        }
        if (current.length > 4) {
            y.setLabel(current[4].toString());
        }
        dataset.setValue((Number) current[2], x, y);
    }

    PlotOrientation plotOrientation = PlotOrientation.HORIZONTAL;
    if (chartDefinition.getActualOrientation() == ChartDefinition.Orientation.VERTICAL) {
        plotOrientation = PlotOrientation.VERTICAL;
    }

    JFreeChart chart = createChart(chartDefinition, dataset, plotOrientation);

    chart.setAntiAlias(antiAlias);

    // impostiamo il bordo invisibile
    // eventualmente e' il css a fornirne uno
    chart.setBorderVisible(borderVisible);

    // impostiamo il titolo
    TextTitle title = chart.getTitle();
    title.setFont(titleFont);
    title.setMargin(10.0, 0.0, 0.0, 0.0);

    // ottieni il Plot
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    CategoryItemRenderer renderer = plot.getRenderer();
    String urlExpression = chartDefinition.getUrlExpression();
    if (!StringUtils.isBlank(urlExpression)) {
        CategoryURLGenerator urlGenerator = new ChartBarUrlGenerator(chartDefinition.getUrlExpression());
        renderer.setBaseItemURLGenerator(urlGenerator);
    } else {
        renderer.setBaseItemURLGenerator(null);
    }
    renderer.setBaseOutlinePaint(Color.BLACK);

    // ///////////////
    if (renderer instanceof BarRenderer || renderer instanceof BarRenderer3D) {
        BarRenderer barRenderer = (BarRenderer) renderer;

        barRenderer.setDrawBarOutline(true);
        barRenderer.setShadowVisible(false);
        barRenderer.setBarPainter(new StandardBarPainter());

        // hongliangpan add
        barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        barRenderer.setBaseItemLabelsVisible(true);
        // ? setSeriesItemLabelGenerator
        barRenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        // bar???
        barRenderer.setMinimumBarLength(0.02);
        // 
        barRenderer.setMaximumBarWidth(0.05);
        // ?????
        // ??90,??/3.14
        ItemLabelPosition itemLabelPositionFallback = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                TextAnchor.BASELINE_LEFT, TextAnchor.HALF_ASCENT_LEFT, -1.57D);
        // ??labelposition
        // barRenderer.setPositiveItemLabelPositionFallback(itemLabelPositionFallback);
        // barRenderer.setNegativeItemLabelPositionFallback(itemLabelPositionFallback);

        barRenderer.setItemLabelsVisible(true);

        // ?
        barRenderer.setBaseOutlinePaint(Color.BLACK);
        // ???
        barRenderer.setDrawBarOutline(true);

        // ???
        barRenderer.setItemMargin(0.0);

        // ?
        barRenderer.setIncludeBaseInRange(true);
        barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        barRenderer.setBaseItemLabelsVisible(true);
        // ?
        plot.setForegroundAlpha(1.0f);
    }

    // ///////////////

    // il plot ha sfondo e bordo trasparente
    // (quindi si vede il colore del chart)
    plot.setBackgroundPaint(transparentColor);
    plot.setOutlinePaint(transparentColor);

    // Modifico il toolTip
    // plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} = {1} ({2})"));

    // imposta il messaggio se non ci sono dati
    plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available"));
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.GRAY);
    plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));

    // Category axis
    CategoryAxis categoryAxis = plot.getDomainAxis();
    categoryAxis.setAxisLinePaint(Color.BLACK);
    categoryAxis.setLabelFont(axisFont);
    categoryAxis.setAxisLineVisible(true);

    // impostiamo la rotazione dell'etichetta
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        CategoryLabelPosition pos = new CategoryLabelPosition(RectangleAnchor.TOP_LEFT,
                TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -Math.PI / 4.0,
                CategoryLabelWidthType.CATEGORY, 100);
        CategoryLabelPositions positions = new CategoryLabelPositions(pos, pos, pos, pos);
        categoryAxis.setCategoryLabelPositions(positions);
        categoryAxis.setMaximumCategoryLabelWidthRatio(6.0f);
        height = 333;
    } else {
        categoryAxis.setMaximumCategoryLabelWidthRatio(0.4f);

        // recuperiamo 8 pixel a sinistra
        plot.setInsets(new RectangleInsets(4.0, 0.0, 4.0, 8.0));

        height = 74;

        // contiamo gli elementi nel dataset
        height += 23 * dataset.getColumnCount();

        height += 57;
    }

    Axis rangeAxis = plot.getRangeAxis();
    rangeAxis.setAxisLinePaint(Color.BLACK);
    rangeAxis.setLabelFont(axisFont);

    DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier());
    plot.setDrawingSupplier(supplier);

    // impostiamo il titolo della legenda
    String legendString = chartDefinition.getLegend();
    Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM,
            HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0));
    subtitle.setMargin(0, 0, 5, 0);
    chart.addSubtitle(subtitle);

    // impostiamo la legenda
    LegendTitle legend = chart.getLegend();
    legend.setBorder(0, 0, 0, 0);
    legend.setItemFont(legendItemFont);
    int legendMargin = 10;
    legend.setMargin(0.0, legendMargin, legendMargin, legendMargin);
    legend.setBackgroundPaint(transparentColor);

    // impostiamo un gradiente orizzontale
    Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, height, Color.WHITE);
    chart.setBackgroundPaint(chartBgPaint);
    return chart;
}

From source file:org.jajuk.ui.views.StatView.java

/**
 * Collection size bars.//  w  w  w  . ja  va 2 s  .  c  o m
 * 
 * @return the chart
 */
private ChartPanel createCollectionSize() {
    try {
        final DateFormat additionFormatter = UtilString.getAdditionDateFormatter();
        CategoryDataset cdata = null;
        JFreeChart jfchart = null;
        int iMonthsNumber = 5; // number of mounts we show, mounts
        // before are set together in 'before'
        long lSizeByMonth[] = new long[iMonthsNumber + 1];
        // contains size ( in Go ) for each month, first cell is before
        // data
        int[] iMonths = getMonths(iMonthsNumber);
        ReadOnlyIterator<Track> tracks = TrackManager.getInstance().getTracksIterator();
        while (tracks.hasNext()) {
            Track track = tracks.next();
            int i = Integer.parseInt(additionFormatter.format(track.getDiscoveryDate())) / 100;
            for (int j = 0; j < iMonthsNumber + 1; j++) {
                if (i <= iMonths[j]) {
                    lSizeByMonth[j] += track.getTotalSize();
                }
            }
        }
        double[][] data = new double[1][iMonthsNumber + 1];
        for (int i = 0; i < iMonthsNumber + 1; i++) {
            data[0][i] = (double) lSizeByMonth[i] / 1073741824;
        }
        cdata = DatasetUtilities.createCategoryDataset(new String[] { "" }, getMonthsLabels(iMonthsNumber),
                data);
        // chart, use local copy of method to use better format string for
        // tooltips
        jfchart = createBarChart3D(Messages.getString("StatView.7"), // chart
                // title
                Messages.getString("StatView.8"), // domain axis label
                Messages.getString("StatView.9"), // range axis label
                cdata, // data
                PlotOrientation.VERTICAL, // orientation
                false, // include legend
                true, // tooltips
                false, // urls
                "{1} = {2} GB");
        CategoryPlot plot = jfchart.getCategoryPlot();
        CategoryAxis axis = plot.getDomainAxis();
        new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT,
                -Math.PI / 8.0, CategoryLabelWidthType.CATEGORY, 0);
        axis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
        // set the background color for the chart...
        plot.setNoDataMessage(Messages.getString("StatView.10"));
        plot.setForegroundAlpha(0.5f);
        plot.setBackgroundAlpha(0.5f);
        // plot.setBackgroundImage(IconLoader.IMAGES_STAT_PAPER).getImage());
        return new ChartPanel(jfchart);
    } catch (Exception e) {
        Log.error(e);
        return null;
    }
}

From source file:com.smhdemo.common.report.generate.factory.ChartFactory.java

public byte[] export(Chart report, Map<String, String> pageParams) throws Exception {
    if (report == null) {
        return null;
    }//  ww w .jav  a 2  s  .c o  m
    DefaultCategoryDataset dataset = buildDataset(report, pageParams);
    java.awt.Font titleFont = new java.awt.Font(report.getFontName(), report.getFontStyle(),
            report.getFontSize());
    String chartTitle = report.getChartTitle();
    chartTitle = replaceParam(pageParams, report.getParameters(), chartTitle, false);
    String horizAxisLabel = report.getHorizAxisLabel();
    horizAxisLabel = replaceParam(pageParams, report.getParameters(), horizAxisLabel, false);
    String vertAxisLabel = report.getVertAxisLabel();
    vertAxisLabel = replaceParam(pageParams, report.getParameters(), vertAxisLabel, false);
    Boolean showLegend = report.getShowLegend();
    Boolean showTooltips = report.getShowTooltips();
    Boolean drillThroughEnabled = false;
    Chart.Type chartType = report.getType();

    CategoryURLGenerator urlGenerator = null;

    JFreeChart chart = null;
    switch (chartType) {
    case VERTBAR:
        chart = ChartGenerationService.createBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
        break;
    case VERTBAR3D:
        chart = ChartGenerationService.createBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
        break;
    case HORIZBAR:
        chart = ChartGenerationService.createBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case HORIZBAR3D:
        chart = ChartGenerationService.createBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case STACKEDVERTBAR:
        chart = ChartGenerationService.createStackedBarChart(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case STACKEDVERTBAR3D:
        chart = ChartGenerationService.createStackedBarChart3D(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case STACKEDHORIZBAR:
        chart = ChartGenerationService.createStackedBarChart(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips,
                drillThroughEnabled, urlGenerator);
        break;
    case STACKEDHORIZBAR3D:
        chart = ChartGenerationService.createStackedBarChart3D(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips,
                drillThroughEnabled, urlGenerator);
        break;
    case VERTLINE:
        chart = ChartGenerationService.createLineChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
        break;
    case HORIZLINE:
        chart = ChartGenerationService.createLineChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case VERTAREA:
        chart = ChartGenerationService.createAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
        break;
    case HORIZAREA:
        chart = ChartGenerationService.createAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case VERTSTACKEDAREA:
        chart = ChartGenerationService.createStackedAreaChart(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case HORIZSTACKEDAREA:
        chart = ChartGenerationService.createStackedAreaChart(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips,
                drillThroughEnabled, urlGenerator);
        break;
    case PIEBYCOLUMN:
        chart = ChartGenerationService.createPieChart(chartTitle, titleFont, dataset, TableOrder.BY_COLUMN,
                showLegend, showTooltips, drillThroughEnabled, null);
        break;
    case PIEBYROW:
        chart = ChartGenerationService.createPieChart(chartTitle, titleFont, dataset, TableOrder.BY_ROW,
                showLegend, showTooltips, drillThroughEnabled, null);
        break;
    case PIEBYCOLUMN3D:
        chart = ChartGenerationService.create3DPieChart(chartTitle, titleFont, dataset, TableOrder.BY_COLUMN,
                showLegend, showTooltips, drillThroughEnabled, null);

        break;
    case PIEBYROW3D:
        chart = ChartGenerationService.create3DPieChart(chartTitle, titleFont, dataset, TableOrder.BY_ROW,
                showLegend, showTooltips, drillThroughEnabled, null);
        break;
    default:
        throw new BaseException("", "");
    }
    try {
        Integer bgColorR = report.getBgColorR();
        Integer bgColorG = report.getBgColorG();
        Integer bgColorB = report.getBgColorB();
        chart.setBackgroundPaint(new java.awt.Color(bgColorR, bgColorG, bgColorB));

        String axisFontName = report.getAxisFontName();
        Integer axisFontStyle = report.getAxisFontStyle();
        Integer axisFontSize = report.getAxisFontSize();
        java.awt.Font axisFont = new java.awt.Font(axisFontName, axisFontStyle, axisFontSize);

        String axisTickFontName = report.getAxisTickFontName();
        Integer axisTickFontStyle = report.getAxisTickFontStyle();
        Integer axisTickFontSize = report.getAxisTickFontSize();
        java.awt.Font axisTickFont = new java.awt.Font(axisTickFontName, axisTickFontStyle, axisTickFontSize);

        String legendFontName = report.getLegendFontName();
        Integer legendFontStyle = report.getLegendFontStyle();
        Integer legendFontSize = report.getLegendFontSize();
        java.awt.Font legendFont = new java.awt.Font(legendFontName, legendFontStyle, legendFontSize);
        Integer tickLabelRotate = report.getTickLabelRotate();

        String dataFontName = report.getDataFontName();
        Integer dataFontStyle = report.getDataFontStyle();
        Integer dataFontSize = report.getDataFontSize();
        java.awt.Font dataFont = new java.awt.Font(dataFontName, dataFontStyle, dataFontSize);

        Plot plot = chart.getPlot();
        if (!(plot instanceof MultiplePiePlot)) {
            CategoryPlot categoryPlot = chart.getCategoryPlot();
            CategoryItemRenderer renderer = categoryPlot.getRenderer();
            renderer.setBaseItemLabelGenerator(new LabelGenerator(0.0));
            renderer.setBaseItemLabelFont(dataFont);
            renderer.setBaseItemLabelsVisible(true);
            if (chartType == Chart.Type.VERTLINE || chartType == Chart.Type.HORIZLINE) {
                LineAndShapeRenderer lineRenderer = (LineAndShapeRenderer) categoryPlot.getRenderer();
                lineRenderer.setBaseShapesVisible(true);
                lineRenderer.setDrawOutlines(true);
                lineRenderer.setUseFillPaint(true);
            }
        }

        if (plot instanceof CategoryPlot) {
            CategoryPlot catPlot = (CategoryPlot) plot;
            catPlot.getDomainAxis().setLabelFont(axisFont);
            catPlot.getRangeAxis().setLabelFont(axisFont);
            catPlot.getDomainAxis().setTickLabelFont(axisTickFont);
            catPlot.getRangeAxis().setTickLabelFont(axisTickFont);
            catPlot.getDomainAxis().setMaximumCategoryLabelWidthRatio(100.0f);
            double angle = -2.0 * Math.PI / 360.0 * (double) tickLabelRotate;
            CategoryLabelPositions oldp = catPlot.getDomainAxis().getCategoryLabelPositions();
            CategoryLabelPositions newp = new CategoryLabelPositions(oldp.getLabelPosition(RectangleEdge.TOP),
                    new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT,
                            TextAnchor.TOP_RIGHT, angle, CategoryLabelWidthType.RANGE, 0.0f),
                    oldp.getLabelPosition(RectangleEdge.LEFT), oldp.getLabelPosition(RectangleEdge.RIGHT));
            catPlot.getDomainAxis().setCategoryLabelPositions(newp);
        } else if (plot instanceof PiePlot3D) {
            PiePlot3D piePlot = (PiePlot3D) plot;
            piePlot.setLabelFont(axisFont);
            piePlot.setDirection(org.jfree.util.Rotation.CLOCKWISE);
            piePlot.setForegroundAlpha(0.5f);
            piePlot.setNoDataMessage("?");
        } else if (plot instanceof PiePlot) {
            PiePlot piePlot = (PiePlot) plot;
            piePlot.setLabelFont(axisFont);
        }
        LegendTitle legend = (LegendTitle) chart.getLegend();
        if (legend != null) {
            legend.setItemFont(legendFont);
            RectangleEdge legendRectEdge = RectangleEdge.BOTTOM;
            Integer legendPosition = report.getLegendPosition();
            switch (legendPosition) {
            case 0:
                legendRectEdge = RectangleEdge.LEFT;
                break;
            case 1:
                legendRectEdge = RectangleEdge.TOP;
                break;
            case 2:
                legendRectEdge = RectangleEdge.RIGHT;
                break;
            case 3:
                legendRectEdge = RectangleEdge.BOTTOM;
                break;
            }
            legend.setPosition(legendRectEdge);
        }
    } catch (Exception e) {
        logger.error("Chart Export Exception", e);
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ChartUtilities.writeChartAsPNG(out, chart, report.getChartWidth(), report.getChartHeight());
    return out.toByteArray();
}

From source file:com.ewcms.plugin.report.generate.factory.ChartFactory.java

public byte[] export(ChartReport report, Map<String, String> pageParams) throws Exception {
    if (report == null) {
        return null;
    }/*from  w  ww.  j  a  v  a 2s  .c om*/
    DefaultCategoryDataset dataset = buildDataset(report, pageParams);
    java.awt.Font titleFont = new java.awt.Font(report.getFontName(), report.getFontStyle(),
            report.getFontSize());
    String chartTitle = report.getChartTitle();
    chartTitle = replaceParam(pageParams, report.getParameters(), chartTitle, false);
    String horizAxisLabel = report.getHorizAxisLabel();
    horizAxisLabel = replaceParam(pageParams, report.getParameters(), horizAxisLabel, false);
    String vertAxisLabel = report.getVertAxisLabel();
    vertAxisLabel = replaceParam(pageParams, report.getParameters(), vertAxisLabel, false);
    Boolean showLegend = report.getShowLegend();
    Boolean showTooltips = report.getShowTooltips();
    Boolean drillThroughEnabled = false;
    ChartReport.Type chartType = report.getType();

    CategoryURLGenerator urlGenerator = null;

    JFreeChart chart = null;
    switch (chartType) {
    case VERTBAR:
        chart = ChartGenerationService.createBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
        break;
    case VERTBAR3D:
        chart = ChartGenerationService.createBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
        break;
    case HORIZBAR:
        chart = ChartGenerationService.createBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case HORIZBAR3D:
        chart = ChartGenerationService.createBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case STACKEDVERTBAR:
        chart = ChartGenerationService.createStackedBarChart(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case STACKEDVERTBAR3D:
        chart = ChartGenerationService.createStackedBarChart3D(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case STACKEDHORIZBAR:
        chart = ChartGenerationService.createStackedBarChart(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips,
                drillThroughEnabled, urlGenerator);
        break;
    case STACKEDHORIZBAR3D:
        chart = ChartGenerationService.createStackedBarChart3D(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips,
                drillThroughEnabled, urlGenerator);
        break;
    case VERTLINE:
        chart = ChartGenerationService.createLineChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
        break;
    case HORIZLINE:
        chart = ChartGenerationService.createLineChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case VERTAREA:
        chart = ChartGenerationService.createAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
        break;
    case HORIZAREA:
        chart = ChartGenerationService.createAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case VERTSTACKEDAREA:
        chart = ChartGenerationService.createStackedAreaChart(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case HORIZSTACKEDAREA:
        chart = ChartGenerationService.createStackedAreaChart(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips,
                drillThroughEnabled, urlGenerator);
        break;
    case PIEBYCOLUMN:
        chart = ChartGenerationService.createPieChart(chartTitle, titleFont, dataset, TableOrder.BY_COLUMN,
                showLegend, showTooltips, drillThroughEnabled, null);
        break;
    case PIEBYROW:
        chart = ChartGenerationService.createPieChart(chartTitle, titleFont, dataset, TableOrder.BY_ROW,
                showLegend, showTooltips, drillThroughEnabled, null);
        break;
    case PIEBYCOLUMN3D:
        chart = ChartGenerationService.create3DPieChart(chartTitle, titleFont, dataset, TableOrder.BY_COLUMN,
                showLegend, showTooltips, drillThroughEnabled, null);

        break;
    case PIEBYROW3D:
        chart = ChartGenerationService.create3DPieChart(chartTitle, titleFont, dataset, TableOrder.BY_ROW,
                showLegend, showTooltips, drillThroughEnabled, null);
        break;
    default:
        throw new BaseException("", "");
    }
    try {
        Integer bgColorR = report.getBgColorR();
        Integer bgColorG = report.getBgColorG();
        Integer bgColorB = report.getBgColorB();
        chart.setBackgroundPaint(new java.awt.Color(bgColorR, bgColorG, bgColorB));

        String axisFontName = report.getAxisFontName();
        Integer axisFontStyle = report.getAxisFontStyle();
        Integer axisFontSize = report.getAxisFontSize();
        java.awt.Font axisFont = new java.awt.Font(axisFontName, axisFontStyle, axisFontSize);

        String axisTickFontName = report.getAxisTickFontName();
        Integer axisTickFontStyle = report.getAxisTickFontStyle();
        Integer axisTickFontSize = report.getAxisTickFontSize();
        java.awt.Font axisTickFont = new java.awt.Font(axisTickFontName, axisTickFontStyle, axisTickFontSize);

        String legendFontName = report.getLegendFontName();
        Integer legendFontStyle = report.getLegendFontStyle();
        Integer legendFontSize = report.getLegendFontSize();
        java.awt.Font legendFont = new java.awt.Font(legendFontName, legendFontStyle, legendFontSize);
        Integer tickLabelRotate = report.getTickLabelRotate();

        String dataFontName = report.getDataFontName();
        Integer dataFontStyle = report.getDataFontStyle();
        Integer dataFontSize = report.getDataFontSize();
        java.awt.Font dataFont = new java.awt.Font(dataFontName, dataFontStyle, dataFontSize);

        Plot plot = chart.getPlot();
        if (!(plot instanceof MultiplePiePlot)) {
            CategoryPlot categoryPlot = chart.getCategoryPlot();
            CategoryItemRenderer renderer = categoryPlot.getRenderer();
            renderer.setBaseItemLabelGenerator(new LabelGenerator(0.0));
            renderer.setBaseItemLabelFont(dataFont);
            renderer.setBaseItemLabelsVisible(true);
            if (chartType == ChartReport.Type.VERTLINE || chartType == ChartReport.Type.HORIZLINE) {
                LineAndShapeRenderer lineRenderer = (LineAndShapeRenderer) categoryPlot.getRenderer();
                lineRenderer.setBaseShapesVisible(true);
                lineRenderer.setDrawOutlines(true);
                lineRenderer.setUseFillPaint(true);
            }
        }

        if (plot instanceof CategoryPlot) {
            CategoryPlot catPlot = (CategoryPlot) plot;
            catPlot.getDomainAxis().setLabelFont(axisFont);
            catPlot.getRangeAxis().setLabelFont(axisFont);
            catPlot.getDomainAxis().setTickLabelFont(axisTickFont);
            catPlot.getRangeAxis().setTickLabelFont(axisTickFont);
            catPlot.getDomainAxis().setMaximumCategoryLabelWidthRatio(100.0f);
            double angle = -2.0 * Math.PI / 360.0 * (double) tickLabelRotate;
            CategoryLabelPositions oldp = catPlot.getDomainAxis().getCategoryLabelPositions();
            CategoryLabelPositions newp = new CategoryLabelPositions(oldp.getLabelPosition(RectangleEdge.TOP),
                    new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT,
                            TextAnchor.TOP_RIGHT, angle, CategoryLabelWidthType.RANGE, 0.0f),
                    oldp.getLabelPosition(RectangleEdge.LEFT), oldp.getLabelPosition(RectangleEdge.RIGHT));
            catPlot.getDomainAxis().setCategoryLabelPositions(newp);
        } else if (plot instanceof PiePlot3D) {
            PiePlot3D piePlot = (PiePlot3D) plot;
            piePlot.setLabelFont(axisFont);
            piePlot.setDirection(org.jfree.util.Rotation.CLOCKWISE);
            piePlot.setForegroundAlpha(0.5f);
            piePlot.setNoDataMessage("?");
        } else if (plot instanceof PiePlot) {
            PiePlot piePlot = (PiePlot) plot;
            piePlot.setLabelFont(axisFont);
        }
        LegendTitle legend = (LegendTitle) chart.getLegend();
        if (legend != null) {
            legend.setItemFont(legendFont);
            RectangleEdge legendRectEdge = RectangleEdge.BOTTOM;
            Integer legendPosition = report.getLegendPosition();
            switch (legendPosition) {
            case 0:
                legendRectEdge = RectangleEdge.LEFT;
                break;
            case 1:
                legendRectEdge = RectangleEdge.TOP;
                break;
            case 2:
                legendRectEdge = RectangleEdge.RIGHT;
                break;
            case 3:
                legendRectEdge = RectangleEdge.BOTTOM;
                break;
            }
            legend.setPosition(legendRectEdge);
        }
    } catch (Exception e) {
        logger.error("Chart Export Exception", e);
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ChartUtilities.writeChartAsPNG(out, chart, report.getChartWidth(), report.getChartHeight());
    return out.toByteArray();
}