|
|
In a pie chart, arc length of each sector is proportional to the quantity which it represents. This chapter will explain you how to use JFreeChart for creating Pie Chart from a given set of business data.
Below example depicts mobile sale with the help of a pie chart. Below is a list of different mobile brands and their sale (units per day).
S.No |
Mobile Brands |
Sales (UNITS per day) |
1 |
Iphone 5S |
20 |
2 |
Samsung Grand |
20 |
3 |
MOTO G |
40 |
4 |
Nokia Lumia |
10 |
Below is the code for creating a Pie Chart by using the above given information This code will help you to embed a pie chart in any AWT based application.
Let’s place the above Java code in PieChart_AWT.java file, and then compile and run it from the command prompted as
If everything works fine, it will compile and run to generate below Pie Graph
If you don’t want to embed your chart in any application, then you can create chart images in the command prompt. JFreeChart allows saving chart images in either JPG or PNG formats.
Let’s re-write the above example to generate a JPEG image from a command line. Below are the two APIs provided by JFreeChart library, which can be used for generating either PNG or JPEG image based on your requirement.
keep the above Java code in PieChart.java file, and then compile and run it from the command prompted as
If everything is working fine, it will compile and run to create a JPEG image file named PieChart.jpeg in your current directory.
|
|
JFreeChart Related Tutorials |
|
---|---|
C++ Tutorial | Core Java Tutorial |
C Tutorial | Android Tutorial |
Java Tutorial |
JFreeChart Related Practice Tests |
|
---|---|
C++ Practice Tests | Core Java Practice Tests |
C Practice Tests | Android Practice Tests |
Active Directory Practice Tests | OpenStack Practice Tests |
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.