Package com.lowagie.examples.directcontent.graphics2D

Source Code of com.lowagie.examples.directcontent.graphics2D.JFreeChartExample

/*
* $Id$
*
* This code is part of the 'iText Tutorial'.
* You can find the complete tutorial at the following address:
* http://itextdocs.lowagie.com/tutorial/
*
* This code 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.
*
* itext-questions@lists.sourceforge.net
*/
package com.lowagie.examples.directcontent.graphics2D;

import com.lowagie.geoforge.utils.LwgUtilJFreeChartToPdf;
import java.io.FileNotFoundException;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

import org.geoforge.demo.GfrFileOutputStream;

/**
* JFreeChart example.
*/
public class JFreeChartExample
{

   /**
    * Creates some PDFs with JFreeCharts.
    * @param args no arguments needed
    */
   public static void main(String[] args)
   {
      System.out.println("JFreeChart example");
      /** the following line is a workaround for JDK 1.5 (fix by Adriaan Joubert) */
      org.jfree.text.TextUtilities.setUseDrawRotatedStringWorkaround(false);
      try
      {
         LwgUtilJFreeChartToPdf.convertToPdf(getBarChart(), 400, 600, (new GfrFileOutputStream("barchart.pdf")).getName());
         LwgUtilJFreeChartToPdf.convertToPdf(getPieChart(), 400, 600, (new GfrFileOutputStream("piechart.pdf")).getName());
         LwgUtilJFreeChartToPdf.convertToPdf(getXYChart(), 400, 600, (new GfrFileOutputStream("xychart.pdf")).getName());
      }
      catch (FileNotFoundException ex)
      {
         Logger.getLogger(JFreeChartExample.class.getName()).log(Level.SEVERE, null, ex);
      }
   }

  

   /**
    * Gets an example barchart.
    * @return a barchart
    */
   public static JFreeChart getBarChart()
   {
      DefaultCategoryDataset dataset = new DefaultCategoryDataset();
      dataset.setValue(40, "hits/hour", "index.html");
      dataset.setValue(20, "hits/hour", "download.html");
      dataset.setValue(15, "hits/hour", "faq.html");
      dataset.setValue(8, "hits/hour", "links.html");
      dataset.setValue(31, "hits/hour", "docs.html");
      return ChartFactory.createBarChart("Popularity of iText pages",
            "Page", "hits/hour", dataset,
            PlotOrientation.VERTICAL, false, true, false);
   }

   /**
    * Gets an example piechart.
    * @return a piechart
    */
   public static JFreeChart getPieChart()
   {
      DefaultPieDataset dataset = new DefaultPieDataset();
      dataset.setValue("iText", 60);
      dataset.setValue("cinema.lowagie.com", 10);
      dataset.setValue("tutorial", 30);
      return ChartFactory.createPieChart(
            "Website popularity",
            dataset,
            true,
            true,
            false);
   }

   /**
    * Gets an example XY chart
    * @return an XY chart
    */
   public static JFreeChart getXYChart()
   {
      XYSeries series = new XYSeries("XYGraph");
      series.add(1, 5);
      series.add(2, 7);
      series.add(3, 3);
      series.add(4, 5);
      series.add(5, 4);
      series.add(6, 5);
      XYSeriesCollection dataset = new XYSeriesCollection();
      dataset.addSeries(series);
      return ChartFactory.createXYLineChart(
            "XY Chart", "X-axis", "Y-axis", dataset,
            PlotOrientation.VERTICAL, true, true, false);
   }
}
TOP

Related Classes of com.lowagie.examples.directcontent.graphics2D.JFreeChartExample

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.