[Jfreechart Developer Guide 1.0.14 Pdf Download

0 views
Skip to first unread message

Facunda Ganesh

unread,
Jun 13, 2024, 5:12:30 AM6/13/24
to voipilpimo

Charts, figures, and graphs enable large sets of data to be more quickly understood and analyzed.It is often said that "a picture is worth a thousand words" because a picture can convey significantoverview and comparative information about data that is much more difficult to glean from the textualdata itself. JFreeChart is an open source (and free) Java-basedlibrary that allows for easy creation of multiple types of high-quality data-centric charts.This powerful library provides a highly approachable API that enables developers new to JFreeChart to rapidlycreate elegant charts representing their data.

JFreeChart supports generation of a wide variety of chart types. They range from common types such as pie charts, bar charts, area charts, line charts, histograms, and Gantt charts to more-specific and less frequently used types such as Candlestick, Wind, and Wafer Map charts. One of the quickest ways to determine the types of charts JFreeChart supports out-of-the-box is to examine the Javadoc API documentation for JFreeChart's ChartFactory class.

jfreechart developer guide 1.0.14 pdf download


Download File 🌟 https://t.co/PTHyhZidGq



The data to be graphically represented in this article's charts comes from the HR schema provided with Oracle Database XE. Figure 1 shows the tables present in the HR schema as shown in the SQL*Plus editor that comes with Oracle Database XE.

Oracle Database XE also provides a highly useful, easy-to-use Web-based administrative tool that is built on Oracle Application Express. Figure 2 demonstrates this tool and again shows some of the objects (tables in this case) in the HR schema.

Oracle Database XE offers several advantages for developers and is a natural fit with JFreeChart. Oracle has made Oracle Database XE available at no cost for development and production. Besides its no-cost advantage, other advantages of this database product include a smaller footprint, easy installation and administration, and the highly useful integrated Web administration tool. Its disadvantages affect primarily large enterprise users, because the drawbacks relate to storage space, memory size, and a smaller feature set than that of traditional Oracle database products. For development and prototyping, and even for small production databases, Oracle Database XE can be exactly the right fit. This is especially true of businesses or projects with very limited budgets.

The Web-based administration tool, shown again in the snapshot in Figure 3, displays some of the most significant limitations of Oracle Database XE. Storage space for an instance of Oracle Database XE is limited to 5 GB (including system tablespace), so the 710 megabytes used so far is depicted in the tool in the screenshot as around 14 percent of that limit. Memory usage is limited to 1 gigabyte, so this instance's 314MB RAM usage is depicted as such. Logging into this administration tool as SYSTEM enables even-more-specific storage and memory information to be displayed on the administrative screens. The screen shot in Figure 3 also shows all of the submenu options the tool offers for managing the database.

JFreeChart is available for download at www.jfree.org/jfreechart/. The single downloaded file contains several JAR files for JFreeChart. Once the downloaded file is uncompressed to the directory of your choice, the classpath of any application using JFreeChart needs to point at least to the jfreechart-1.0.5.jar and jcommon-1.0.9.jar files. You can handle this by adding these JAR files to your favorite IDE's project. For building and running outside of an IDE, Java SE 6 allows wildcards to be used for specifying JARs in classpaths, so the JARs in the JFreeChart lib directory can all be included with a single *.jar expression in the classpath. Other than uncompressing the distribution file and pointing your application's classpath at the appropriate JFreeChart JAR files, no significant installation effort is required.

Figure 4 shows the dependent JAR files necessary to build and run most of the code examples in this article. The two JFreeChart JARs mentioned earlier are listed, along with JARs for iText (for PDF generation), Batik (for SVG generation), and Oracle JDBC (for Java access of the Oracle database). Even if you are not using JDeveloper, Figure 4 displays in a single location the dependencies you will need to place in your classpath to build and run most of the tools discussed in this article.

The JFreeChart compressed distribution file also includes a build.xml file that is especially useful for generating JFreeChart Javadoc-based documentation. To generate the JFreeChart documentation, run the "javadoc" target on the provided Ant build.xml file (run "ant javadoc" in the "ant" subdirectory). Assuming that you have Ant installed, this will generate a "javadoc" subdirectory under the directory in which the JFreeChart files were extracted and will place the generated Javadoc files in that directory. The Javadoc documentation for JFreeChart is also available online at the JFreeChart Web site.

JFreeChart comes with many packages, classes, and interfaces, but you need to understand only a surprisingly small number of them to start using JFreeChart. This section briefly covers some of the key classes and interfaces that are fundamental to using JFreeChart and that are used in examples in this article.

One of the most important classes in the JFreeChart library is itself called JFreeChart. This class provides a representation of a Java 2D chart. Methods on this class enable developers to control various aspects of a generated chart and to create an Abstract Window Toolkit (AWT) BufferedImage representing the chart. You can create several simple types of charts by using JFreeChart directly, with very little extra effort, but JFreeChart provides access to delegates such as Plot that allow for more control over the rendered charts.

The ChartFactory class is used to create different types of charts. Each of the static methods of this class is named after the type of chart it produces, and each of these methods returns an instance of the generic JFreeChart class, regardless of the type of chart involved. Scanning the Javadoc documentation for this class can provide many insights and is one of the easiest ways to determine the basic chart types provided out-of-the-box by JFreeChart.

Similar to the ChartFactory class, the ChartUtilities class has numerous static methods. Most of the methods this class provides handle conversion of a chart to an image format or to basic HTML image maps.

Examination of the ChartFactory chart creation methods indicates that each of these methods accepts some type of Dataset-extended interface (note Dataset in the class's name) as a parameter. The generated Javadoc documentation for the Dataset interface shows that it is extended by several subinterfaces and implemented by an even greater number of concrete classes.

The Dataset subinterfaces to use for various types of charts are typically obvious, because the chart type's name often appears in the interface name. For example, PieDataset is used for pie charts and XYDataset is used for many x,y-type charts. CategoryDataset is used for line and area charts, and other subinterfaces that extend the Dataset interface are used for other chart types.

Dataset subinterfaces are the mechanism for providing data to the ChartFactory class to be represented in a chart. A concrete implementation of the appropriate Dataset subinterface is created and populated and passed to ChartFactory's appropriate create***Chart method, where *** is the pertinent chart type.

The Dataset interface JFreeChart provides should not be confused with the Dataset interface provided by JDBC 4. The JFreeChart-provided Dataset interface does not have to be populated from the database or be related to the database in any way. Instead, the JFreeChart Dataset interface and its subinterfaces are designed for populating JFreeChart charts with data.

Much of the remainder of this article is devoted to illustrating some of JFreeChart's features and how easy it is to begin using JFreeChart. This illustration of JFreeChart's usability and feature set is accomplished through a series of code examples with snapshots of the produced charts. As each of the examples is presented, pertinent points related to each specific example are presented, along with additional general JFreeChart concepts.

Most of the examples in this article involve creating charts with JFreeChart, based on data stored in the HR schema provided with Oracle Database XE. Because we are charting data stored in the database, the JDBC-oriented Dataset classes are particularly convenient. This initial example shows how to chart the number of employees in each department in a pie chart.

Listing 1 demonstrates how easy it is to create a chart based on data stored in the database. The databaseAccess.getOracleDbConnection() method, not shown here, is a simple method that provides an Oracle database connection (returns a java.sql.Connection).

As Listing 1 demonstrates, only two significant Java code statements are required to produce a pie chart from the database. The appropriate Dataset is created and then passed to the ChartFactory's createPieChart method, which returns the JFreeChart containing the generated pie chart. A JDBCPieDataset was constructed and passed a database connection and a database SQL query string. Because that concrete class implements the PieDataset interface, we could then pass that, via the interface, to the createPieChart method. The catch block for SQLException in this code listing was necessary because the JDBCPieDataset constructor throws the checked exception SQLException.

Once we have a chart created and in the form of an instance of the JFreeChart class, there are several things we can do with the chart. One of the easiest things to do with a created chart is to write it to the file system as an image file. The code in Listing 2 illustrates use of ChartUtilities to write our newly created JFreeChart to the file system as a PNG formatted image.

795a8134c1
Reply all
Reply to author
Forward
0 new messages