com.pureinfo.srm.reports.impl.MyChartFactory.java Source code

Java tutorial

Introduction

Here is the source code for com.pureinfo.srm.reports.impl.MyChartFactory.java

Source

/**
 * PureInfo JFdemo
 * @(#)MyChartFactory.java   1.0 2006-6-28
 * 
 * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. 
 * All rights reserved, see the license file.
 * 
 * www.pureinfo.com.cn
 */

package com.pureinfo.srm.reports.impl;

import java.awt.Paint;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryAxis3D;
import org.jfree.chart.axis.NumberAxis3D;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.chart.urls.StandardCategoryURLGenerator;
import org.jfree.data.category.CategoryDataset;
import org.jfree.util.SortOrder;

/**
 * <P>
 * Created on 2006-6-28 9:48:58<BR>
 * Last modified on 2006-6-28
 * </P>
 * TODO describe MyChartFactory here ...
 * 
 * @author elmar.chen
 * @version 1.0, 2006-6-28
 * @since JFdemo 1.0 
 */
public class MyChartFactory {
    public static JFreeChart createBarChart3D(String title, String categoryAxisLabel, String valueAxisLabel,
            CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {

        if (orientation == null) {
            throw new IllegalArgumentException("Null 'orientation' argument.");
        }
        CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel);
        ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel);

        BarRenderer3D renderer = new BarRenderer3D() {
            /**
             * @see org.jfree.chart.renderer.AbstractRenderer#getItemPaint(int, int)
             */
            public Paint getItemPaint(int _nRow, int _nColumn) {
                return getSeriesPaint(_nColumn);
            }
        };
        if (tooltips) {
            renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
        }
        if (urls) {
            renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
        }

        CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
        plot.setOrientation(orientation);
        if (orientation == PlotOrientation.HORIZONTAL) {
            // change rendering order to ensure that bar overlapping is the 
            // right way around
            plot.setRowRenderingOrder(SortOrder.DESCENDING);
            plot.setColumnRenderingOrder(SortOrder.DESCENDING);
        }
        plot.setForegroundAlpha(0.75f);

        JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

        return chart;

    }
}