Java Learning Notes Production chart process (Eclipse+jfreechart) __java

Source: Internet
Author: User
Tags pear

The

Jfreechart is a Java project on the open source site SourceForge.net, which is used primarily to generate a variety of charts, including pie, histogram (plain column and stack bar), line, area, distribution, blending, Gantt Chart and some dashboard and so on. These different patterns of graphs can basically meet the current requirements. The company's main products are as follows:
         1, Jfreereport: report resolution Tools
          2, Jfreechart:java Graphics solution (application/applet/servlet/jsp)
          3, Jcommon:jfreereport and Jfreechart common class libraries
          4, jfreedesigner:jfreereport report design tool

The chart generated by Jfreechart consists of three parts: Title,plot (the main display area of the graph) and Legend

One of the ongoing data analysis software needs to be charted using Java graphics Engine Jfreechart, which is described in its configuration process in eclipse as follows:
1. Download jfreechart:http://www.jfree.org/jfreechart/index.html
2. Installation configuration: First decompression jfreechart-1.0.9.zip, and then after the extracted files in the \ Gnujaxp.jar,jcommon-1.0.12.jar,jfreechart-1.0.9.jar three jar packages under Lib are added to project. The specific practices in Eclipse are: Project menu-->properties-->java build Path-->libraries-->add External Jars, In this way, add the three jar files to the current project.
3. Based on Jfreechart programming
The following is an online search for a program segment that uses Jfreechart to generate a histogram to test the success of the configuration.

Import java.io.*;
Import java.awt.Dimension;
Import Javax.swing.JPanel;
Import org.jfree.chart.*;
Import Org.jfree.chart.axis.CategoryAxis;
Import org.jfree.chart.axis.CategoryLabelPositions;
Import Org.jfree.chart.plot.CategoryPlot;
Import org.jfree.chart.plot.PlotOrientation;
Import Org.jfree.chart.renderer.category.BarRenderer3D;
Import Org.jfree.data.category.CategoryDataset;
Import Org.jfree.data.category.DefaultCategoryDataset;
Import org.jfree.data.general.DatasetUtilities;
Import Org.jfree.ui.ApplicationFrame;
Import org.jfree.ui.RefineryUtilities;
                /** * This class is used to demonstrate the simplest column graph generation/public class Barchartdemo {public static void main (string[] args) throws ioexception{
                Categorydataset DataSet = GetDataSet2 (); 
                                                        Jfreechart chart = Chartfactory.createbarchart3d ("Fruit yield map",//Chart title
                                              "Fruit",//the display label of the catalogue axis          "Output",//value axis display label DataSet,//DataSet
                                                        Plotorientation.vertical,//Chart Orientation: horizontal, vertical True,//whether to display the legend (for a simple histogram must be false) false,/
                                                        /whether to generate tool false//whether URL link is generated
                );
                FileOutputStream fos_jpg = null;
                      
                        try {fos_jpg = new FileOutputStream ("d:\\fruit.jpg");
                Chartutilities.writechartasjpeg (fos_jpg,chart,400,300);
                        Finally {try {fos_jpg.close (); The catch (Exception e) {}}}/** * Gets a demo simple DataSet object * @rEturn * * private static Categorydataset GetDataSet () {Defaultcategorydataset DataSet = N
                EW Defaultcategorydataset ();
                Dataset.addvalue (MB, NULL, "Apple");
                Dataset.addvalue (=, null, "pear");
                Dataset.addvalue (+, NULL, "grapes");
                Dataset.addvalue (n, NULL, "banana");
                Dataset.addvalue (+, NULL, "Litchi");
        return dataset; /** * Get a demo of the combined DataSet object * @return * * private static Categorydataset GetDataSet2
                () {Defaultcategorydataset DataSet = new Defaultcategorydataset ();
                Dataset.addvalue (100, "Beijing", "Apple");
                Dataset.addvalue (100, "Shanghai", "Apple");
                Dataset.addvalue (100, "Guangzhou", "Apple");
                Dataset.addvalue (200, "Beijing", "pear");
                Dataset.addvalue (200, "Shanghai", "pear");
                Dataset.addvalue (200, "Guangzhou", "pear"); Dataset.addvalue (300, "Beijing"), "grapes");
                Dataset.addvalue (300, "Shanghai", "grapes");
                Dataset.addvalue (300, "Guangzhou", "Grape");
                Dataset.addvalue (400, "Beijing", "banana");
                Dataset.addvalue (400, "Shanghai", "banana");
                Dataset.addvalue (400, "Guangzhou", "banana");
                Dataset.addvalue (500, "Beijing", "Litchi");
                Dataset.addvalue (500, "Shanghai", "Litchi");
                Dataset.addvalue (500, "Guangzhou", "Litchi");
        return dataset;
 }
}


.4 Generated Charts
The column chart generated by the above procedure is as follows:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.