Java learning notes chart creation process (eclipse + jfreechart)

Source: Internet
Author: User
Tags pears

Jfreechart is a Java project on the open source site sourceforge.net. It is mainly used to generate a variety of charts, including: pie chart, bar chart (General bar chart and stack bar chart), line chart, Area Chart, distribution chart, hybrid chart, Gantt chart, and some dashboard. These charts of different types can basically meet the current requirements. The company's main products include:
1. jfreereport: Report solution Tool
2. jfreechart: Java graphics solution (Application/applet/servlet/jsp)
3. jcommon: public class libraries of jfreereport and jfreechart
4. jfreedesigner: jfreereport report design tool

Jfreechart generates three charts: title, plot (main display area of the image), and legend.

A data analysis software in progress needs to use Java's chart engine jfreechart for plotting. The configuration process in eclipse is described as follows:
1. Download jfreechart: http://www.jfree.org/jfreechart/index.html
2. Install the configuration: First decompress jfreechart-1.0.9.zip, and then decompress the decompressed file \ Lib under the gnujaxp. jar, jcommon-1.0.12.jar, jfreechart-1.0.9.jar Three jar package added to the project. The specific practices in eclipse are as follows: Project menu --> properties --> JAVA build path --> libraries --> Add external jars, add the preceding three jar files to the current project one by one.
3. jfreechart-based programming
The following is a program segment on the Internet that uses jfreechart to generate a bar chart to test 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 bar chart generation */public class barchartdemo {public static void main (string [] ARGs) throws ioexception {categorydataset dataset = getdataset2 (); jfreechart chart = chartfactory. createbarchart3d ("fruit yield Chart", // chart title "Fruit", // display label of the Directory axis "yield", // display label of the value axis dataset, // dataset plotorientation. vertical, // chart direction: horizontal, vertical true, // whether to display the legend (for a simple column chart, it must be false) false, // generate tool false // generate URL link); fileoutputstream fos_jpg = NULL; try {fos_jpg = new fileoutputstream ("d :\\ fruit.jpg"); chartutilities. writechartasjpeg (fos_jpg, chart, 400,300);} finally {try {fos_jpg.close ();} catch (exception E) {}}/ *** get a simple DataSet object used in the demo * @ return */Private Static categorydataset getdataset () {defaultcategorydataset dataset = new defaultcategorydataset (); dataset. addvalue (100, null, "apple"); dataset. addvalue (200, null, "Pear"); dataset. addvalue (300, null, "grape"); dataset. addvalue (400, null, "banana"); dataset. addvalue (500, null, "litchi"); Return dataset;}/*** get a combined DataSet object for demonstration * @ return */Private Static categorydataset getdataset2 () {defacategcategorydataset dataset = new defaultcategorydataset (); dataset. addvalue (100, "Beijing", "apple"); dataset. addvalue (100, "Shanghai", "apple"); dataset. addvalue (100, "Guangzhou", "apple"); dataset. addvalue (200, "Beijing", "Pears"); dataset. addvalue (200, "Shanghai", "Pears"); dataset. addvalue (200, "Guangzhou", "Pears"); dataset. addvalue (300, "Beijing", "grape"); dataset. addvalue (300, "Shanghai", "grape"); 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 bar chart generated by the above program 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.