/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Java is a trademark or registered trademark of Sun Microsystems, Inc. * in the United States and other countries.] * * ------------------ * BarChartDemo1.java * ------------------ * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): ; * * $Id: BarChartDemo1.java,v 1.1.2.1 2005/10/25 20:41:32 mungady Exp $ * * Changes * ------- * 09-Mar-2005 : Version 1, copied from the demo collection that ships with * the JFreeChart Developer Guide (DG); * * C# version was written by Kazuya Ujihara. */ using System; using System.Collections.Generic; using System.Text; using System.Drawing; using System.Drawing.Drawing2D; using org.jfree.chart; using org.jfree.chart.plot; using org.jfree.data.category; using org.jfree.data.general; using org.jfree.ui; using org.jfree.chart.title; using org.jfree.chart.block; using org.jfree.chart.axis; using org.jfree.chart.renderer.category; namespace Ujihara.Demo { public class BarChartDemo1 : ChartCreator { public override JFreeChart CreateChart() { return CreateChart(CreateDataset()); } /** * Returns a sample dataset. * * @return The dataset. */ private static CategoryDataset CreateDataset() { // row keys... string series1 = "First"; string series2 = "Second"; string series3 = "Third"; // column keys... string category1 = "Category 1"; string category2 = "Category 2"; string category3 = "Category 3"; string category4 = "Category 4"; string category5 = "Category 5"; // create the dataset... DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(1.0, series1, category1); dataset.addValue(4.0, series1, category2); dataset.addValue(3.0, series1, category3); dataset.addValue(5.0, series1, category4); dataset.addValue(5.0, series1, category5); dataset.addValue(5.0, series2, category1); dataset.addValue(7.0, series2, category2); dataset.addValue(6.0, series2, category3); dataset.addValue(8.0, series2, category4); dataset.addValue(4.0, series2, category5); dataset.addValue(4.0, series3, category1); dataset.addValue(3.0, series3, category2); dataset.addValue(2.0, series3, category3); dataset.addValue(3.0, series3, category4); dataset.addValue(6.0, series3, category5); return dataset; } /** * Creates a sample chart. * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart CreateChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart( "Bar Chart Demo", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.White); // get a reference to the plot for further customisation... CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.LightGray); plot.setDomainGridlinePaint(Color.White); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.White); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer)plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... java.awt.GradientPaint gp0 = new java.awt.GradientPaint( 0.0f, 0.0f, java.awt.Color.blue, 0.0f, 0.0f, new java.awt.Color(0, 0, 64)); java.awt.GradientPaint gp1 = new java.awt.GradientPaint( 0.0f, 0.0f, java.awt.Color.green, 0.0f, 0.0f, new java.awt.Color(0, 64, 0)); java.awt.GradientPaint gp2 = new java.awt.GradientPaint( 0.0f, 0.0f, java.awt.Color.red, 0.0f, 0.0f, new java.awt.Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0) ); // OPTIONAL CUSTOMISATION COMPLETED. return chart; } } }