Jfreechart learning example

Source: Internet
Author: User
Tags pears

Jfreechart is an open class library for drawing charts on the Java platform. It is fully written in Java and designed for applications, applets, Servlets, and JSP.

Jfreechart can generate a pie chart (PIE), bar, plots, and time)Gantt Chart(Gantt) and other charts, and can generate PNG and jpg (JPEG) output, can also be associated with PDF and excel.

Jfreechart is a pretty good Java graphics solution that can basically meet the current graphics needs,Official download

Before using the jfreechart plug-in Java, you must first import the jar package
Right-click the project name --> build path --> Configure build path... --> libraries --> Add extenal jars --> select the jar package

-----------------------------------------------------------------


Jfreechart-Line Graph

Import Java. io. *; </P> <p> Import Org. jfree. data. *; <br/> Import Org. jfree. chart. *; <br/> Import Org. jfree. chart. plot. *; </P> <p> public class linechart {<br/> Public static void main (string [] ARGs) throws ioexception {<br/> categorydataset dataset = getdataset2 (); <br/> jfreechart chart = chartfactory. createlinechart (<br/> "fruit yield Chart", // Title <br/> "Fruit", // directory axis (horizontal) <br/> "yield ", // numeric axis (vertical) <br/> dataset, // dataset <br/> plotorientation. vertical, // chart direction (horizontal/vertical) <br/> true, // whether to display the legend (required for a simple bar chart) <br/> false, // generate tool <br/> false // generate URL link <br/>); </P> <p> fileoutputstream fos_jpg = NULL; <br/> try {<br/> fos_jpg = new fileoutputstream (". /fruit4.jpg "); // image output directory <br/> chartutilities. writechartasjpeg (fos_jpg, 100, chart, 800,600, null); <br/>}finally {<br/> try {<br/> fos_jpg.close (); <br/>} catch (exception e) {<br/> E. printstacktrace (); <br/>}</P> <p> Private Static categorydataset getdataset2 () {<br/> defaultcategorydataset dataset = new defaultcategorydataset (); <br/> dataset. addvalue (100, "Beijing", "apple"); <br/> dataset. addvalue (600, "Beijing", "Pears"); <br/> dataset. addvalue (700, "Beijing", "grape"); <br/> dataset. addvalue (300, "Beijing", "banana"); <br/> dataset. addvalue (200, "Beijing", "litchi"); <br/> dataset. addvalue (100, "Guangzhou", "apple"); <br/> dataset. addvalue (400, "Guangzhou", "Pears"); <br/> dataset. addvalue (600, "Guangzhou", "grape"); <br/> dataset. addvalue (500, "Guangzhou", "banana"); <br/> dataset. addvalue (200, "Guangzhou", "litchi"); <br/> dataset. addvalue (100, "Shanghai", "apple"); <br/> dataset. addvalue (300, "Shanghai", "Pears"); <br/> dataset. addvalue (900, "Shanghai", "grape"); <br/> dataset. addvalue (400, "Shanghai", "banana"); <br/> dataset. addvalue (200, "Shanghai", "litchi"); <br/> return dataset; <br/>}< br/>}

:

-----------------------------------------------------------------

Jfreechart -- pie Pie Chart

Import Java. io. *; </P> <p> Import Org. jfree. data. *; <br/> Import Org. jfree. chart. *; </P> <p> public class piechart {</P> <p> Public static void main (string [] ARGs) throws ioexception {<br/> defaultpiedataset DATA = getdataset (); <br/> jfreechart chart = chartfactory. createpiechart3d (<br/> "fruit yield Chart", // Title <br/> data, // data <br/> true, <br/> false, <br/> false <br/>); </P> <p> fileoutputstream fos_jpg = NULL; <br/> try {<br/> fos_jpg = new fileoutputstream (". /fruit3_pie.jpg "); <br/> chartutilities. writechartasjpeg (fos_jpg, 100, chart, 800,600, null); <br/>}finally {<br/> try {<br/> fos_jpg.close (); <br/>} catch (exception e) {<br/> E. printstacktrace (); <br/>}</P> <p> Private Static defaultpiedataset getdataset () {<br/> defaultpiedataset dataset = new defaultpiedataset (); <br/> dataset. setvalue ("apple", 100); <br/> dataset. setvalue ("Pear", 200); <br/> dataset. setvalue ("Grapes", 300); <br/> dataset. setvalue ("Bananas", 400); <br/> dataset. setvalue ("litchi", 500); <br/> return dataset; <br/>}< br/>}:

-----------------------------------------------------------------

Recommendation reference:

Jfreechart example

General example of jfreechart

Server Tomcat v6.0 server at localhost failed to start

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.