Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use JFreeChart

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of how to use JFreeChart, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to use JFreeChart. Let's take a look at it.

First, JFreeChart acquisition.

JFreeChart is a project of JFreeChart on the open source website SourceForge.net. The company's main products are as follows:

1. JFreeReport: report solving tool

2. JFreeChart:Java graphics solution (Application/Applet/Servlet/Jsp)

3. Common class libraries of JCommon:JFreeReport and JFreeChart

4. The report design tool of JFreeDesigner:JFreeReport

Let's take jfreechart_0.9.21.zip as an example to illustrate.

II. JFreeChart configuration and installation

1. Decompress jfreechart_0.9.21.zip to the specified location, where source is the source code of jfreechart and jfreechart-0.9.21-demo.jar is the example program (this part is left to you to study)

2. In order to configure successfully, we need to pay attention to the following three files: jfreechart-0.9.21.jar, libjcommon-0.9.6.jar, and libgnujaxp.jar

3. If it is Application development, copy the above three files to% JAVA_HOME%LIB, and add to the environment variable CLASSPATH if it is WEB development, take TEST, a WEB project in TOMCAT, as an example:

Copy the above three files into TESTWEB-INFLIB, and then modify the TESTWEB-INFweb.xml file by adding the following code:

DisplayChart org.jfree.chart.servlet.DisplayChart DisplayChart / servlet/DisplayChart

At this point, the configuration of jfreechart is complete, and now you are ready for jfreechart development. What is worth mentioning here is that the compatibility of jfreechart class structure before and after design is not very good. The class library structure may be different in different versions of jfreechart, and sometimes you may need to check the source code. If it is displayed in Chinese, you may need to change the font of the source code according to the look and feel, but I personally think this version is better than the previous version.

III. Introduction of JFreeChart function

JFreeChart is currently a * java graphics solution, which can basically meet the current graphics needs, including the following aspects:

Pie charts (2D and 3D): pie chart (planar and stereoscopic)

Bar charts (regular and stacked, with an optional 3D effect): bar chart

Line and area charts: graphs

Scatter plots and bubble charts time series, high/low/open/close charts and candle stick charts: sequence diagram

Combination charts: composite diagram

Pareto charts Gantt charts: Gantt Chart

Wind plots, meter charts and symbol charts wafer map charts

(state chart, pie chart (2D and 3D), bar chart (horizontal, vertical), line chart, dot chart, time change chart, Gantt chart, stock market chart, mixed chart, thermometer chart, scale chart and other common commercial charts)

Drawings can be exported to PNG and JPEG formats, and can also be associated with PDF and EXCEL.

Introduction to the JFreeChart core class library:

Study of jfreechart source code found that the source code is mainly composed of two large packages: org.jfree.chart,org.jfree.data. The former is mainly related to the graphics itself, while the latter is related to the data displayed by the graphics. If you are interested in the specific research, you can study it yourself. I will tell you how to study the source code in the future.

The main core classes are:

Org.jfree.chart.JFreeChart: chart object, the final representation of any type of chart is to customize some properties in this object. The JFreeChart engine itself provides a factory class for creating different types of chart objects

Org.jfree.data.category.XXXDataSet: a dataset object that provides the data used to display the chart. According to different types of charts, there are many types of dataset object classes.

Org.jfree.chart.plot.XXXPlot: chart area object, which basically determines what kind of chart. When creating this object, you need the support of Axis, Renderer and dataset objects.

Org.jfree.chart.axis.XXXAxis: two axes for working with charts: vertical axis and horizontal axis

Org.jfree.chart.render.XXXRender: responsible for how to display a chart object

Org.jfree.chart.urls.XXXURLGenerator: mouse-click links used to generate each item in the Web diagram

XXXXXToolTipGenerator: help tips for generating images. Different types of charts correspond to different types of tooltip classes.

IV. JFreeChart Development (Application/Applet)

1. The developer who lives in Application, pie charts, the code is as follows:

/ * * Description:This application is the first jfreechart * Datetime:20058-02-11 * / package demo; import org.jfree.chart.JFreeChart; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; import org.jfree.data.general.DefaultPieDataset; public class FirstJFreeChart {public FirstJFreeChart () {} public static void main (String [] args) {DefaultPieDataset dpd = new DefaultPieDataset (); dpd.setValue ("Manager", 25) Dpd.setValue ("marketer", 25); dpd.setValue ("developer", 45); dpd.setValue ("others", 5); / / Create JFreeChart object / / parameters can see the source code JFreeChart pieChart = ChartFactory.createPieChart ("CityInfoPort company organization chart", dpd,true,true,false); ChartFrame pieFrame = new ChartFrame ("CityInfoPort company organization chart", pieChart); pieFrame.pack (); pieFrame.setVisible (true);}}

The above example can be further improved as follows:

/ * * Description:This application is the first jfreechart * Datetime:20058-02-11 * / package com.cityinforport.demo; import org.jfree.chart.JFreeChart; import org.jfree.chart.ChartPanel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; import org.jfree.data.general.DefaultPieDataset; import org.jfree.chart.plot.PiePlot; import org.jfree.data.general.PieDataset; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities Import java.awt.Font; import javax.swing.*; public class FirstJFreeChart extends ApplicationFrame {/ / constructor public FirstJFreeChart (String s) {super (s); setContentPane (createDemoPanel ());} public static void main (String [] args) {FirstJFreeChart fjc = new FirstJFreeChart (CityInfoPort Company Organization Chart); fjc.pack (); RefineryUtilities.centerFrameOnScreen (fjc); fjc.setVisible (true) } / / generate pie chart dataset object public static PieDataset createDataset () {DefaultPieDataset defaultpiedataset = new DefaultPieDataset (); defaultpiedataset.setValue ("Manager", 10.02D); defaultpiedataset.setValue ("marketer", 20.23D); defaultpiedataset.setValue ("developer", 60.02D); defaultpiedataset.setValue ("OEM personnel", 10.02D); defaultpiedataset.setValue ("others", 5.11D); return defaultpiedataset } / / generate chart master object JFreeChart public static JFreeChart createChart (PieDataset piedataset) {/ / define chart object JFreeChart jfreechart = ChartFactory.createPieChart ("CityInfoPort Company Organization Chart", piedataset,true,true,false); / / get chart display object PiePlot pieplot = (PiePlot) jfreechart.getPlot (); / / set chart label font pieplot.setLabelFont (new Font ("SansSerif", Font.BOLD,12); pieplot.setNoDataMessage ("No data available") Pieplot.setCircular (true); pieplot.setLabelGap (0.01D); / / spacing return jfreechart;} / / generate a panel public static JPanel createDemoPanel () {JFreeChart jfreechart = createChart (createDataset ()); return new ChartPanel (jfreechart);}}

two。 Living in the development of Web, I would like to declare here that we want to put the three files jfreechart-0.9.21.jar, libjcommon-0.9.6.jar and libgnujaxp.jar into WEB-INF\ lib, OK, let's take a look at this example.

Welcome to Jfreechart!

This is the end of the article on "how to use JFreeChart". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to use JFreeChart". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 269

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report