Java objects of JFreechart

xiaoxiao2021-03-06  20

Java objects of JFreechart

Blog China Category: Java Technology,

JFreeChart is an excellent open source Java 2D project. The disadvantage is that there is a lack of documentation, and in Chinese, Chinese. This article is the second part of experience summary

Second, JFreeChart's coordination relationship

The drawing object of JFreechart consists of org.jfree.chart.jfreechart, but the graphich2d as a drawing key is set in org.jfree.chart.Render. *, it is set in the corresponding render class package, in other words, the developer can pass the basic chart Plate Graphic settings, complete the necessary drawing scheduled effect design; and most modifications can actually use each class of packaging without directly modifying the Graphic object attribute (who remembers?). JFreechart's data interface is made from different PLOT packages in org.jfree.chart.plot. *, which corresponds to different DataSet, located in org.jfree.chart.data. * Different DataSet interface packages. The key to use the JFreeChart mapping is to have a corresponding dataset object, and then package into a corresponding one of the plot Plot objects, and finally package into different JFreeChart object delivery output. The above steps can be done step by step by the New method. In other words, the PLOT class is a graphic design, render is a drawn tool, while DataSet is a padded data; then the three key factors of the map are abstracted into unified interfaces, mutual matching various graphics. For a chart that may have multiple sets of data sets, such as a plurality of curves (like a few stocks), incoming PLOT is not a data set, but a collection of data sets, generally named a certain collection.

Different CHART types are generated by different methods of ChartFactory, which can reduce the amount of operation of DataSet to different CHART objects accordingly, and obtain a CHART object directly. In fact, it is necessary to generate the necessary render and PLOT classes instead of the user, if the user does not want to use the default setting, you need to make another corresponding PLOT object by the GET method. The last image output of JFreeChart is generally complete by org.jfree.chart.chartutilites, which can output the completed Chart object to the transmitted PrintWriter object. In the server program, another ServerUtilites method calls this method to generate an image temporary file and return to this file object to JSP or Servlet, binding the lifecycle of this image with session, and wants to achieve buffer function, reduce the server Dynamically generates the loss of the image. But there is a big problem that one is that if the session is very long, it is equal to the unable to generate real-time images, and the second is that there are more people, the burden on the server seems to be increased. This algorithm obviously has problems, it is better to modify it into time to update an image.

Observe the code, the effect is the same:

A, factory method:

JFreeChart Chart = ChartFactory.createPieChart3d (2000 GDP Distribution Scale Diagram ", DATA, TRUE, FALSE, FALSE); // Specify different implementation Chart objects, containing different PLOT plot objects PIEPLOT PLOT = (PIEPLOT) Chart.getPlot ); // Get the PLOT object for amendment property, forced shape to call the respective method Plot.setLabelgenerator ("{0} = {2}", Numberformat.getNumberinstance (), Numberformat.getPercentInstance ()))) ; // Set the annotation mode plot.setForegroundalpha (0.5F); // Set Transparency Plot.SetNodataMessage ("No Record Content"); // No Record Anomaly Display B, Manually Generate Object

PIEPLOT PLOT = New PIEPLOT (Dataset);

Plot.setLabelgenerator ("{0} = {2}", NumberFormat.getNumberinstance (), Numberformat.getPercentInstance ())); // Set Note Way Plot.SetForeGroundalpha (0.5F); // Set Transparency Plot.setNodataMessage ("No Content"); // No recording exception display

JFreeChart Chart = new jfreechart ("", jfreechart.default_title_font, plot, false;

转载请注明原文地址:https://www.9cbs.com/read-43623.html

New Post(0)