Project JFreeChart which was released in 2000 is an open source library (Open Source) for Java, which allows you to create diagrams in a practical and simple. With JFreeChart can make different kinds of graphics ranging from the common types such as pie charts , bar charts, area charts, line charts, histograms, Gantt charts, more specific and less types often used as Candlestick, Wind and Wafer Map. For more information on this review Javadoc documentation and ChartFactory JFreeChart classes.
I. - Conditions |
- JFreeChart package, which you can download from http://sourceforge.net/projects/jfreechart/ although JFreeChart official site is http://www.jfree.org/jfreechart/
- JCommon package, it downloads http://sourceforge.net/projects/jfreechart/files/3.% 20JCommon /
- The JFreeChart documentation (optional).
You must download download the JFreeChart package, optionally also recommend downloading the package JCommon. Even a partial version of it is already included in JFreeChart.
II-SETTING AND THE JFreeChart JCOMMON |
then begin the steps to configure JFreeChart in NetBeans IDE:
- Once downloaded the package and the package JFreeChart JCommon unzip it into a directory on the PC.
- Now open the NetBeans to configure JCommon libraries JFreeChart and therefore in NetBeans we go to the Tools menu and select Libraries:
- We click on New Library and type "JCommon-1.0.16" as the name of the library then go to the tab Classpath → Add Jar / Folder and then seek the direction of JCommon downloaded above and select the file JCommon-1.0.16.jar:
- Do the same with the jar JFreeChart unload the eye in the jar we selected in this case is the lib folder.
- done this and have set up libraries in JFreeChart and NetBeans JCommon; hour and we can generate a graph.
III .- CREATING A GRAPHIC ON USING JFreeChart NETBEANS |
- create a new project, for this go to File menu → New Projct → Java Application and leave the Create Main Class enabled us to generate the main class (this is not essential for the generation can be placed on a graphics class by itself - just for sake of the example we are going to do so -)
- And now in the Main class will post the following:
jfreechart package, import
org.jfree.chart.ChartFactory;
org.jfree.chart.ChartFrame import, import
org.jfree.chart.JFreeChart ;
org.jfree.data.general.DefaultPieDataset import;
public class Main {public static void
main (String [] args) {
/ / Create a dataset
DefaultPieDataset DefaultPieDataset data = new ();
data . setValue ("Categría 1", 43.2);
data.setValue (Categría 2 ", 27.9);
data.setValue (" Categría 3 ", 79.5);
/ / Create a Chart
JFreeChart chart = ChartFactory.createPieChart (
" JFreeChart Example ", / / \u200b\u200bTítrulo
chart data,
true, / / \u200b\u200bLegend
true, / / \u200b\u200btrue
ToolTips )
/ / create a kind of frame and display the JFreeChart it
/ / This constructor calls us the title of the chart and the chart created
ChartFrame frame = new ChartFrame (First for javax0711 Chart ", chart);
frame.pack ();
frame.setVisible (true);
}}
- compile, run the application and ready and we have our first graph generated
0 comments:
Post a Comment